Microsoft XML SDK 2.6 - XML and XSL Samples

IXMLDOMSelection Examples

Typical XPath Caching Scenario

Set up the compiled XPath expression object:

xmldoc.setProperty("SelectionLanguage", "XPath")
var xpath = xmldoc.selectNodes("foo/morefoo/evenmorefoo");

Next, load an XML document:

xmldoc.async = false;
xmldoc.load ("http://server/someXML.xml");

Finally, apply the XPath selection to the entire document tree and walk the matching nodes:

xpath.context = xmldoc; //this is redundant in this case
var node;
while ((node = xpath.nextNode()) != NULL)
{
   //do something with each node here
}