Programming XPath

The following examples illustrate how to use XPath with two commonly used XML processors.

XPath and MSXML 2.6 (and Above)

The following Javascript code executes and XPath expression against the MSXML DOM implementation and displays the results:

 // make sure arguments are correct if (WScript.Arguments.length != 2) { WScript.echo("usage: xpath fname xpath:xpathExpr"); WScript.Quit(1); } // get XML file name and xpath expression string var fname = WScript.Arguments.Item(0); var xpe = WScript.Arguments.Item(1); // echo expression WScript.echo(xpe); // create DOM for input document var dom = new ActiveXObject("MSXML2.DOMDocument"); // set the selection language to XPath, the default for // MSXML 2.6 and above is XSL Patterns dom.setProperty("SelectionLanguage", ...

Get Essential XML: Beyond Markup now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.