I'm trying to locate an element that has certain text value in one of its child. For example,
<peers>
<peer>
<offset>1</offset>
<tag>TRUE</tag>
</peer>
<peer>
<offset>2</offset>
<tag>FALSE</tag>
</peer>
</peers>
from this XML document I would like to directly locate tag in a peer element whose offset value is 1.
So for that purpose I have a XPath expression as follows:
./peers/peer[offset='1']/tag
however using such expression in ElementTree's Element.find() method fails and gives None rather than the "tag" element of my interest:
from xml.etree.ElementTree import fromstring
doc = fromstring("<peers><peer><offset>1</offset><tag>TRUE</tag></peer><peer><offset>2</offset><tag>FALSE</tag></peer></peers>")
tag = doc.find("./peers/peer[offset='1']/tag")
print tag
=> None
I'm being inclined to believe it's either my above XPath expression is wrong, or due to ElementTree's supporting only a subset of XPath according to its documentation. Looking for help. Thank you.