xpathFind method is not working as expected.
Hi Team,
I upgraded java-xmlbuilder library from v0.4 to 0.6 or 1.2 and I start seeing failures related to "XPathExpressionException", Please see below the complete error message:
If I revert back to 0.4 it starts working, could someone please help me with this?
Regards, Arjun
Hi @arjunlodhe I expect the problem you're experiencing is due to the improved namespace support that was added in version 0.5:
Namespace support when building document, and when performing xpath queries
Since versions after 0.4 are aware of namespaces and their prefix names, you must either:
- include the prefix in your XPath queries (e.g.
xpathFind("//my-ns-prefix:TABLE_INFO")) or if you only have a single default namespace you can leave out its name (e.g.xpathFind("//:TABLE_INFO")) - create with an XMLBuilder/2 object that has namespaces disabled via the
isNamespaceAwareoptional param, e.g.XMLBuilder.parse(xmlFile, false, false)(withenableExternalEntitiesandisNamespaceAwareboolean flags)
See this section of the unit tests for examples of how to handle namespaces in XPath queries: https://github.com/jmurty/java-xmlbuilder/blob/master/src/test/java/com/jamesmurty/utils/BaseXMLBuilderTests.java#L403-L485