You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
javax.xml.xpath.XPathExpressionException: XPath expressi on "TABLE_INFO/field[tag='aggregate-count']" does not resolve to an Element in context [aggregate-information: null]: null
at com.jamesmurty.utils.BaseXMLBuilder.xpathFindImpl(BaseXMLBuilder.java:505)
at com.jamesmurty.utils.XMLBuilder.xpathFind(XMLBuilder.java:372)
at com.jamesmurty.utils.XMLBuilder.xpathFind(XMLBuilder.java:378)
If I revert back to 0.4 it starts working, could someone please help me with this?
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 isNamespaceAware optional param, e.g. XMLBuilder.parse(xmlFile, false, false) (with enableExternalEntities and isNamespaceAware boolean flags)
Activity
jmurty commentedon Sep 1, 2024
Hi @arjunlodhe I expect the problem you're experiencing is due to the improved namespace support that was added in version 0.5:
Since versions after 0.4 are aware of namespaces and their prefix names, you must either:
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"))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