This sample uses TestDriver, an executable, and two classes: XPathWrapper and XPathWrapperImp.
What it does: TestDriver 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
TestDriver 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
TestDriver foo.xml /doc name/@last
and
TestDriver foo.xml //name[position()="4"]./@first
See also: Working with XPath expressions.