I have the following xml
<collection>
<item>
<id>001</id>
<attributes>
<attr1>A</attr1>
</attributes>
</item>
<item>
<id>002</id>
<attributes>
<attr1>A</attr1>
</attributes>
</item>
<item>
<id>003</id>
<attributes>
<attr1>B</attr1>
</attributes>
</item>
</collection>
I need my xpath query to return me "true" if all attr1='A'. I tried with this but it returns "true" even if only one attr1="A".
//item/attr1/text()='A'
Your current XPath is returning true because there is at least one
attr1element that has atext()value ofA.You could test whether the count of
attr1elements is equal to the count ofattr1elements that havetext()with the valueA:Or you could evaluate an expression to test that there are
not()anyattr1elements that are not equal toA: