Fast select by ID using XPathNavigator API : XmlPathNavigator « XML « C# / CSharp Tutorial






/*
<orders>
  <order orderno="id10952" date="4/15/96" shipAddress="Str. 57"/>
  <order orderno="id2" date="6/13/95" shipAddress="Road  2312"/>   
</orders>
*/
using System;
using System.Xml; 
using System.IO;
using System.Text;
using System.Xml.XPath;
class MainClass{
  public static void Main(string[] args){
        XmlDocument doc = new XmlDocument();
        doc.Load("d:/orders.xml");
        //Fast select by ID using XPathNavigator API
        XPathNavigator nav = doc.CreateNavigator();
        if (nav.MoveToId("id2"))
          Console.WriteLine(nav.GetAttribute("shipAddress", ""));
          

  }

}








30.23.XmlPathNavigator
30.23.1.XPathNavigator: XPathNodeIterator with comparison
30.23.2.XPathNavigator: Evaluate
30.23.3.Create XPathNavigator object by calling CreateNavigator of XmlDocument
30.23.4.XPathNodeIterator from a select-node statement
30.23.5.Select a node
30.23.6.Get Node information by using XPathNavigator
30.23.7.Move to a child with XPathNavigator
30.23.8.Fast select by ID using XPathNavigator API