Search code examples
javaxmlxpathvtd-xml

VTD-XML: how to execute XPath query not from the root element


I need to handle large XML files, and I decided to move from DOM parser to VTD-XML.

When I used Java's DOM parser, I could evaluate XPath queries from any node, not from the root. Look at XPath.evaluate prototype:

Object evaluate(String expression,
                Object item,
                QName returnType)
                   throws XPathExpressionException

Object item is the starting context (a node, for example). This is very useful.

But I can't find the way to do the same in VTD-XML. I have read its API and read many examples, for instance, this one, but everywhere queries are executed from the root.

How to do that?


Solution

  • Ok, it seems I got it: actually, XPath queries are always executed relative to the current VTDNav's cursor position.

    Check out this example, look for the section "Nested XPath support".