Mega Code Archive

 
Categories / C# / XML
 

XPathNavigator WriteSubtree outputs node and its child nodes to the XmlWriter

/* <?xml version="1.0" encoding="utf-8"?> <book genre="Programming" publicationdate="2010" ISBN="1-111111-11-0" xmlns="http://www.domain.com/books">     <title>C#</title>     <author>         <first-name>A</first-name>         <last-name>B</last-name>     </author>     <price>8.99</price> </book> */ using System; using System.Linq; using System.Xml; using System.Xml.Linq; using System.Collections; using System.Collections.Generic; using System.Xml.XPath; public class MainClass{    public static void Main(){                      XPathDocument document = new XPathDocument("domainBooks.xml");         XPathNavigator navigator = document.CreateNavigator();                  navigator.MoveToChild("bookstore", "http://www.domain.com/books");         navigator.MoveToChild("book", "http://www.domain.com/books");                  XmlWriter writer = XmlWriter.Create("domainBook.xml");         navigator.WriteSubtree(writer);                  writer.Close();    } }