Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xpathFind method is not working as expected. #26

Open
arjunlodhe opened this issue Aug 1, 2024 · 1 comment
Open

xpathFind method is not working as expected. #26

arjunlodhe opened this issue Aug 1, 2024 · 1 comment

Comments

@arjunlodhe
Copy link

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:

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?

Regards,
Arjun

@jmurty
Copy link
Owner

jmurty commented 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:

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)

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants