Home
Manage Your Code
Snippet: Select an XML node and update its inner text. (C#)
Title: Select an XML node and update its inner text. Language: C#
Description: Use the SelectSingleNode() method to select a node and then update its inner text. Views: 207
Author: Aaron Crandall Date Added: 8/29/2007
Copy Code  
1string xml = "<Entity EntityType=\"Manufacturer\">";
2xml += "<Name></Name><XPath /><URL></URL></Entity>";
3
4XmlDocument doc = new XmlDocument();
5doc.LoadXml(xml);
6
7XmlNode nodeName = doc.SelectSingleNode("Entity/Name");
8nodeName.InnerText = "ACME";
9
10-----------------------------------
11Now, the xml looks like this:
12-----------------------------------
13<Entity EntityType="Manufacturer"><Name>ACME</Name><XPath /><URL></URL></Entity>