/*//p that refer to the root node do work when operating with a context node that is not part of a document. However, the query / (return the root node) throws an
XPathException
when applied to a node that is not part of the document. Furthermore the top-level node in the tree is treated as the first and only child of the root node, not as the root node itself. For instance, this query stores
parent
in the
result
variable, not
child
:
Element parent = new Element("parent"); Element child = new Element("child"); parent.appendChild(child); Nodes results = child.query("/*"); Node result = result.get(0);
@param xpath the XPath expression to evaluate
@param namespaces a collection of namespace prefix bindings used in the XPath expression
@return a list of all matched nodes; possibly empty
@throws XPathException if there's a syntax error in the expression, the query returns something other than a node-set