In Xpath, I am wanting to select elements that equal a specific value.
Sample XML data:
<aaa id="11" >
<aaa id="21" >
<aaa id="31" ></aaa>
<bbb id="32" >
<aaa id="41" ></aaa>
<bbb id="42" ></bbb>
<ccc id="43" ></ccc>
<ddd id="44" >qwerty</ddd>
<ddd id="45" ></ddd>
<ddd id="46" ></ddd>
</bbb>
</aaa>
<bbb id="22" >
<aaa id="33" >qwerty</aaa>
<bbb id="34" ></bbb>
<ccc id="35" ></ccc>
<ddd id="36" ></ddd>
<ddd id="37" ></ddd>
<ddd id="38" ></ddd>
</bbb>
<ccc id="23" >qwerty</ccc>
<ccc id="24" ></ccc>
</aaa>
Now, using the XPath:
//ccc[.='qwerty']
I get the correct, expected results:
Name Value
ccc qwerty
Now, using the XPath:
//aaa[.='qwerty']
I get unexpected results:
Name Value
aaa
aaa qwerty
And what I am particularly interested, is how to select any element with that value
XPath:
//*[.='qwerty']
I get very strange unexpected results:
Name Value
aaa
bbb
ddd qwerty
bbb qwerty
aaa qwerty
ccc qwerty
Can someone explain these results, and how to fix my XPath expressions to get more expected results?
. =
is different than XPathtext() =
. See matching text nodes is different than matching string values to learn why. – kjhughes