This sample uses an executable (TestDriver in Windows, XPathWrapper in Linux and AIX), and two classes: XPathWrapper and
XPathWrapperImp.
What it does: The executable passes XPathWrapper an XML file name, a context node location path, and an XPath
expression. XPathWrapper in turn passes these arguments to the XPathWrapperImpl evaluate() method, which executes the
XPath expression from specified context node in the XML document and returns the nodes it finds (if any).
 | You can use this sample as an aid when you want to find out what a given XPath expression returns from a
given context node in an XML file. |
Run this sample from the XPathWrapper subdirectory with
Windows:
TestDriver XMLFile ContextNode XPathExpression
Linux or AIX:
XPathWrapper XMLFile ContextNode XPathExpression
where XMLFile is an XML source file, ContextNode is the location path to the context
node, and XPathExpression is an XPath expression to apply to that context node. The XPathWrapper
subdirectory contains an XML file named xml.foo (part of it appears below).
 |  |  |
 | <?xml version="1.0"?>
<doc>
<name first="David" last="Marston"/>
<name first="David" last="Bertoni"/>
...
<name first="Paul" last="Dick"/>
</doc> |  |
 |  |  |
You can try command lines like
Windows:
TestDriver foo.xml /doc name/@last
Linux or AIX:
XPathWrapper foo.xml /doc name/@last
and
Windows:
TestDriver foo.xml / '//name[position()="4"]/@first'
Linux or AIX:
XPathWrapper foo.xml / '//name[position()="4"]/@first'
 | If an XPathWrapper argument includes characters (such as *) that the shell intercepts, enclose the argument
in double quotes. |
See also: Working with XPath expressions.