xpathcommand-lineconfigurationsaxonxpath-3.1

How to use XPath 3.1 in Saxon?


I am currently using XPath 3.1 syntax but for some reason Saxon outputs the error:

To use XPath 3.1 syntax, you must configure the XPath parser to handle it.

How do I do this?

Many thanks!!!


Solution

  • If you're using the s9api API, use XPathCompiler.setLanguageVersion("3.1").

    If you're using JAXP, that's probably a bad idea because the JAXP XPath API can't handle the richness of XPath 3.1 data types; but if you must, cast the XPath object to net.sf.saxon.xpath.XPathEvaluator; then call getStaticContext().setXPathLanguageLevel().

    In Saxon 9.7 the default XPath language level supported is 3.0, because that's the latest W3C spec that has reached Recommendation status.

    UPDATE

    In Saxon 9.8, XPath 3.1 is the default.