XPath Query Demo

image_pdfimage_print
   
 

using System;
using System.Xml;
using System.Xml.XPath;

public class XPathQuery {

  public static void Main(string [] args) {

    string filename = "inventory.xml";
    string xpathExpression = "//inventory/items";

    XmlDocument document = new XmlDocument( );
    document.Load(filename);

    XmlTextWriter writer = new XmlTextWriter(Console.Out);
    writer.Formatting = Formatting.Indented;

    XmlNode node = document.SelectSingleNode(xpathExpression);
    node.WriteTo(writer);

    writer.Close( );
  }
}

/*
<inventory>
  <date year="2006" month="8" day="27" />
  <items>
    <item quantity="5" productCode="01" description="PHP"  unitCost="9.95" />
    <item quantity="3" productCode="02" description="Perl" unitCost="4.95" />
  </items>
</inventory>
*/
           
         
     


This entry was posted in XML-RPC. Bookmark the permalink.