Helpful Information
 
 
Category: ASP.NET
Update XML textNode ASP.Net/VB.Net

Does anyone know a way and/or a tutorial that shows how to update a XML textNode value?

ex:

XMLDoc
<ParentNode>
<ChildNode1>
<ValueNode1>SomeData</ValueNode1>
<ValueNode2>SomeMoreData</ValueNode2>
<ValueNode3>EvenMoreData</ValueNode3>
</ChildNode1>
</ParentNode>

I would like to know how to change,

<ValueNode2>SomeMoreData</ValueNode2>

To

<ValueNode2>UpdatedMoreData</ValueNode2>

language VB.Net/Asp.Net

Before anything else, you might want to bookmark this...

http://samples.gotdotnet.com/QuickStart/howto/default.aspx?url=/quickstart/howto/doc/xml/overviewofxml.aspx :)

Like most things in .NET, there are multiple ways of handling tasks, depending on your needs. Here's a simple snippet that opens an XML document, updates a node, and saves the document.


Imports System.Xml

'.....

Dim loXMLDoc As XmlDocument = New XmlDocument
Dim loNode As XmlNode

loXMLDoc.Load("C:\Path\To\Document.xml")
loNode = loXMLDoc.SelectSingleNode("//ParentNode/ChildNode1/ValueNode2")
loNode.InnerText = "UpdatedMoreData"
loXMLDoc.Save("C:\Path\To\Document.xml")

loNode = Nothing
loXMLDoc = Nothing

I've been looking around for days to find a SIMPLE sample - anbd this is just it - I can use this to read a value then update it - SIMPLE!

CHEERS!:thumbsup:

I tried doing this with a function and failed... what am I doing wrong?

Code that is very similar to this has worked for me in the past. Using SelectSingleNode is probably the most efficient way to do this.










privacy (GDPR)