Mega Code Archive

 
Categories / C# / XML
 

XPathNavigator AppendChild Creates a child node using XML data string

using System; using System.Linq; using System.Xml; using System.Xml.XPath; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; public class MainClass {     public static void Main()     {         XmlDocument document = new XmlDocument();         document.Load("domainBooks.xml");         XPathNavigator navigator = document.CreateNavigator();         navigator.MoveToChild("bookstore", "http://www.domain.com/books");         navigator.MoveToChild("book", "http://www.domain.com/books");         navigator.AppendChild("<pages>100</pages>");         Console.WriteLine(navigator.OuterXml);     } } /* <?xml version="1.0" encoding="utf-8" ?> <bookstore xmlns="http://www.domain.com/books">     <book genre="Programming" publicationdate="2010-03-22" ISBN="1-111111-11-0">         <title>C#</title>         <author>             <first-name>A</first-name>             <last-name>B</last-name>         </author>         <price>8.99</price>     </book>     <book genre="data" publicationdate="2010-11-17" ISBN="0-201-11111-2">         <title>XML</title>         <author>             <first-name>D</first-name>             <last-name>E</last-name>         </author>         <price>11.99</price>     </book>     <book genre="web" publicationdate="2010-02-15" ISBN="1-111111-57-6">         <title>HTML</title>         <author>             <name>A</name>         </author>         <price>9.99</price>     </book> </bookstore> */