I am upgrading from XPath 1.0 to XPath 3.1. I used the library javax.xml.xpath
for XPath 1.0 and am now using the Saxon-HE
library. It was fairly straightforward to migrate the code and I used the S9API interface for the evaluation of the expressions as suggested by saxon.
There is however one little part of code that I can not seem to figure out how to migrate:
public static Object getXpathValueFromContentMap(String name, Map<String, Object> content, boolean list) {
try {
if (list) {
return newArrayList(JXPathContext.newContext(content).iterate(name));
} else {
return JXPathContext.newContext(content).getValue(name);
}
} catch (JXPathNotFoundException ignore) {
return null;
}
}
This method evalutes an xpath expression on a map. Can this be done using the saxon library and if so, how?
JXPath (which I haven't come across before) appears to be an implementation of XPath 1.0 over (an XML node view of) Java data structures such as maps and arrays.
Saxon doesn't have anything similar. With XPath 3.1 it would be much more appropriate to interpret Java maps and arrays as XPath 3.1 maps and arrays, rather than going via an XML node view. However, the XPath expressions for doing that will be significantly different.
It's theoretically possible to provide an XML mapping in Saxon over an external data structure but it's a significant amount of work and that doesn't seem the right approach. But it rather depends on how much XPath code you've got that needs converting.