Mega Code Archive

 
Categories / C# / XML
 

XPathNavigator Select Selects a node set, using the specified XPath expression

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("books.xml");       XPathNavigator navigator = document.CreateNavigator();              XPathNodeIterator nodes = navigator.Select("/bookstore/book");       nodes.MoveNext();       XPathNavigator nodesNavigator = nodes.Current;              XPathNodeIterator nodesText = nodesNavigator.SelectDescendants(XPathNodeType.Text, false);              while (nodesText.MoveNext())           Console.WriteLine(nodesText.Current.Value);    } }