XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("books.xml"); XPathNavigator navigator = xmlDoc.CreateNavigator(); XPathNodeIterator nodes = navigator.Select("//title"); while (nodes.MoveNext()) { Console.WriteLine(nodes.Current.Value); }
XmlDocument xmlDoc = new XmlDocument(); xmlDoc.Load("books.xml"); XPathNavigator navigator = xmlDoc.CreateNavigator(); XPathNodeIterator nodes = navigator.Select("//book[price > 20]"); while (nodes.MoveNext()) { Console.WriteLine(nodes.Current.OuterXml); }Brief Description of Examples: - Example 1 shows how to use XPathNodeIterator to iterate through 'title' elements in an XML document using an XPath query. - Example 2 shows how to use XPathNodeIterator to iterate through 'book' elements in an XML document that have a 'price' element with a value greater than 20 using an XPath query. Package Library: System.Xml.XPath is part of the .NET Framework Class Library.