I'm trying to figure out how to use XPath to get the exceptionID and instrumentID values out of the XML snippet in the following XML document (yes having XML in the CDATA is a little odd, but that's what I get from the 3rd party service)
<?xml version="1.0"?>
<exception>
<info>
<![CDATA[
<info>
<exceptionID>1</exceptionID>
<instrumentID>1</instrumentID>
</info>
]]>
</info>
</exception>
Is it possible to get the values in one XPath statement?
I'm using javax.xml.xpath.XPath inside Java (JDK 1.5 with Xalan 2.7.1 and Xerces 2.9.1), e.g.
XPath xpath = XPathFactory.newInstance().newXPath();
Long exceptionId = new Long(((Double)xpath.evaluate(this.exceptionIdXPath,
document, XPathConstants.NUMBER)).longValue());
It's the this.exceptionIdXPath variable that I'm not sure how to set, I know for example that:
/exception/info/text()/info/exceptionID
won't work (text() returns the data inside the CDATA but with no 'knowledge' that it is XML)
parse-xml(/exception/info)/info/exceptionID
using parse-xml saxonica.com/documentation/functions/intro/parse-xml.xml, Saxon 9.3 saxonica.com is implemented in Java and supports XPath 3.0 in its commercial versions. – Martin Honnen