Select an XML node and update its inner text.

Agosto 30th, 2007

Description: Use the SelectSingleNode() method to select a node and then update its inner text.

Link: http://www.codekeep.net/snippets/933523ac-1fc6-43ca-9d48-b12ad588a2c7.aspx

string xml = "<Entity EntityType=\"Manufacturer\">";
xml += "<Name></Name><XPath /><URL></URL></Entity>";

XmlDocument doc = new XmlDocument();
doc.LoadXml(xml);

XmlNode nodeName = doc.SelectSingleNode("Entity/Name");
nodeName.InnerText = "ACME";

-----------------------------------
Now, the xml looks like this:
-----------------------------------
<Entity EntityType="Manufacturer"><Name>ACME</Name><XPath /><URL></URL></Entity>

  • .NET
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Trackback URI | Comments RSS

Leave a Reply

You must be logged in to post a comment.