Skip to content

xpathFind method is not working as expected. #26

Open

Description

@arjunlodhe

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

Activity

  1. jmurty commented on Sep 1, 2024

    @jmurty
    Owner

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions