1

When evaluating an XPath for expression in Java, example:

        String expr = "for $x in * return $x";

        NodeList nodeList = (NodeList) m_xpath.evaluate(
                expr, 
                docXML, XPathConstants.NODESET);

I get an error:

        javax.xml.xpath.XPathExpressionException: javax.xml.transform.TransformerException: Extra illegal tokens: '$', 'x', 'in', ...

I realize I could simply use * as the value of expr, but I am trying to understand how to use the XPath for expressions in Java.

0

1 Answer 1

4

Despite other answers and comments, for $x in * return $x is XPath. However, for requires XPath 2.0 (or greater), but the default implementation of the javax.xml.xpath API only supports XPath 1.0.

Consider using Saxonica's implementations for excellent XPath 2.0+ support in Java (and .NET).

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.