JAXP XPath API in Java 9

I've just become aware of enhancements to the XPath API in Java 9

http://www.oracle.com/technetwork/java/javase/9-new-features-3745613.html

Nothing very exciting here: no support for XPath versions later than 1.0 (or even recognition that different versions exist); no fix for the horrible NamespaceContext object. But some interesting changes all the same. I copy the summary below.

Impact: Java 9 extends the API to include a new method evaluateExpression that explicitly returns DOM nodes; it is therefore no longer possible to fully implement this API against an object model other than DOM, despite the fact that the XPathFactory class still provides mechanisms for requesting other object models.

Taken together with the lack of support for later XPath versions, as far as Saxon is concerned this makes supporting the JAXP XPath API even less viable. It's tempting to respond by restricting Saxon's support of the JAXP XPath API to be DOM-only, forcing users to use the s9api interface with object models other than DOM.

Here's the summary of changes (note that "the XPath specification" here means "the XPath 1.0 specification")

xml/javax.xml.xpath
XPath enhancement 
Java SE 9 improves the javax.xml.xpath API with new APIs that make use of modern language features to facilitate ease of use and extend support of the XPath specification.

Support ANY type
javax.xml.xpath supported explicit data types defined by the XPath specification. However, it was missing the important ANY type without which the XPath API assumes that an explicit type is always known, which is not true in some circumstances. The new API now supports the ANY type so that an XPath evalution can be performed when the return type is unknown.

Improved ease of use
For ease of use, four new evaluateExpression methods are added to the javax.xml.xpath.XPath and javax.xml.xpath.XPathExpression interfaces to allow specifying explicit types as follows:

When specified explicitly, the new methods return the specific types, including Boolean, Double, Integer, Long, String and org.w3c.dom.Node.
When the return type is expected to be NODESET, the new methods will return a new XPathNodes type. XPathNodes is a new interface that extends Iterable<Node> which makes it easier to use than the traditional org.w3c.dom.NodeList.
When the return type is unknown or ANY, the new methods return a new XPathEvaluationResult type. XPathEvaluationResult provides an XPathResultTypeenum that defines the supported types that are ANY, BOOLEAN, NUMBER, STRING, NODESET, and NODE.

Received on Saturday, 12 May 2018 22:39:33 UTC