Search code examples
javaxpathtalendsaxon

Cannot compare xs:string to xs:integer


Currently running a code on Talend and it throws up this error

net.sf.saxon.trans.XPathException: Cannot compare xs:string to xs:integer at net.sf.saxon.expr.GeneralComparison.typeCheck(GeneralComparison.java:255)

when the saxon 9 is added to the configuration but when its removed it works fine. Any ideas why its interfering with the xpath


Solution

  • Which version of Saxon, precisely, did you add to the Configuration?

    Prior to Saxon 9.6, the Saxon jar file included a manifest indicating that it was a JAXP XPath service provider. As a result, any application code trying to create an XPath provider using the JAXP factory method (XPathFactory.newInstance()) would pick up Saxon if it happened to be on the classpath. Unfortunately the JAXP API is not sufficiently rigorous that all XPath providers are interchangeable; in particular, you have no way of saying that you need an XPath 1.0 engine rather than an XPath 2.0 or XPath 3.1 engine. As a result (and as I am speculating has happened here), an application that was assuming XPath 1.0 behaviour (such as automatic casting of integers to strings in a comparison) might fail because the presence of Saxon on the classpath meant it was actually running XPath 2.0 or later.

    To solve this problem releases from Saxon 9.6 onwards no longer declare themselves to be XPath service providers, and you must now instantiate Saxon directly rather than through the JAXP factory mechanism. But if you're using a version earlier than 9.6, the problem will still be there.

    You can find out which version you have got by running

    java -cp saxon9.jar net.sf.saxon.Version