Mega Code Archive

 
Categories / C# / XML
 

XPathNavigator Clone creates a XPathNavigator positioned at the same node

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("descendant::book[author/last-name='E']");         while (nodes.MoveNext())         {             XPathNavigator clone = nodes.Current.Clone();             clone.MoveToFirstChild();             Console.WriteLine("Book title: {0}", clone.Value);         }     } }