Mega Code Archive

 
Categories / C# / XML
 

XPathNavigator NavigatorComparer Gets an IEqualityComparer used for equality comparison of XPathNavigator objects

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();           Hashtable table = new Hashtable(XPathNavigator.NavigatorComparer);                      // Add nodes to the Hashtable.           foreach (XPathNavigator navigator2 in navigator.Select("//book"))           {               object value = navigator2.Evaluate("string(./title)");               table.Add(navigator2.Clone(), value);               Console.WriteLine("Added book with title {0}", value);           }                      Console.WriteLine(table.Count);           Console.WriteLine("Does the Hashtable have the book \"XML\"?");           Console.WriteLine(table.Contains(navigator.SelectSingleNode("//book[title='XML']")));    } }