I'm using XPATH 1.0 to fetch some nodes from an XML document which uses a default namespace on the root and on nodes with attributes. The attributeFormDefault = "qualified"
is set on the schema.
<Transaction xmlns="http://example.com/transaction">
<someElement/>
<collection>
<value p0:Name="SomeName" xmlns:p0="http://example.com/transaction">some value</value>
<value p1:Name="SomeOtherName" xmlns:p1="http://example.com/transaction">some other value</value>
</collection>
<differentCollection>
<value p2:Name="SomeName" xmlns:p2="http://example.com/transaction">not this one</value>
</differentCollection>
</Transaction>
My aim is to get the /Transaction/collection/value[@Name='SomeName']
node.
The only solution I've found so far seems a little broad:
//*[@*='SomeName']
I could also get the entire collection of <value>
nodes by using:
//*[local-name()='value']
With the namespace restriction in mind, is there a cleaner, more precise way get the node I'm after? 3rd party javascript libraries are not an option.
EDIT
Thanks for the quick responses. I'll note here that by adding a default namespace prefix, solved the xpath query expressions:
<t:Transaction xmlns:t="http://example.com/transaction">
Now i can do:
/t:Transaction/t:collection/t:value[@t:Name='SomeName']