javaxpathsaxon

Cannot compare xs:integer to xs:string - suppress error at XPath compile time


I am using Saxon 9 in Java to compile XPath expressions like this:

net.sf.saxon.xpath.XPathEvaluator.compile(expression)

I am aware of the changes between XPath 1 and XPath 2, so I am not surprised that Saxon cannot evaluate expressions like position() = '1'.

However, is there a way to at least compile, not evaluate the expression?

It would be much easier and more robust to recursively detect and fix type incompatibilities like the one above in a compiled Expression object, than to rely on string operations and regex.


Solution

  • No, there is no supported/tested mechanism in Saxon to invoke XPath parsing without also invoking type checking. However, it's open source code so you could work out what internal interfaces you could call to achieve this effect. The class XPathParser and its key methods like parse() are public.