public CreateNavigator ( ) : |
||
return |
using System; using System.Xml; public class Example { public static void Main() { XmlDocument doc = new XmlDocument(); doc.Load("books.xml"); XPathNavigator navigator = doc.CreateNavigator(); Console.WriteLine(navigator.OuterXml); } }
using System; using System.Xml; public class Example { public static void Main() { XmlDocument doc = new XmlDocument(); doc.LoadXml("In this example, we create an XmlDocument object and initialize its contents with an XML string. Next, we create an XPathNavigator object and use its Select method to query the document using an XPath expression. The expression selects all child nodes with an id attribute equal to '2'. Finally, we print out the XML of the selected node. The System.Xml namespace is the package library used for the XmlDocument and XPathNavigator classes in C#."); XPathNavigator navigator = doc.CreateNavigator(); XPathNodeIterator iterator = navigator.Select("/root/child[@id='2']"); while(iterator.MoveNext()) { Console.WriteLine(iterator.Current.OuterXml); } } } Hello World