Sandeep.Mulawad
Sandeep.Mulawad

Reputation: 21

finding the element in xml having namespace using the element path

Currently i am having a xml as below.

<ns0:transaction>
    <ns0:node1> asdf</ns0:node1>
    <ns0:node2> asdf</ns0:node2>
    <ns0:node3> asdf</ns0:node3>
</ns0:transaction>

And i am having the path /transaction/node1 . But due to the namespace the java code which i am using is not able to fetch the data. Can you please suggest any alternative java code. I am not allowed to use the namespace in the path i am having.

Regards,

Upvotes: 1

Views: 78

Answers (1)

Chris Z
Chris Z

Reputation: 357

Try the xpath

/*[local-name()='transaction']/*[local-name()='node1']

The result of the local-name function is the element name without the namespace prefix

Upvotes: 1

Related Questions