Microsoft XML 2.5 SDK


 
[This is preliminary documentation and subject to change.]

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
}

Contains Example

Given some XML:

<root>
     <elem1>
             <elemA>
     </elem1>
     </elem2>
</root>

After loading xmldoc (containing the above XML)

myElem1 = xmldoc.documentElement.childNodes.item(0);
myElemA = myElem1.childNodes.item(0);

xpath.expr = "root/elem1/elemA";

Assert