I’ve used Element Tree for a while and i love it because of its simplicity
But I’m doubting of its implementation of x path
This is the XML file
<a>
<b name="b1"></b>
<b name="b2"><c/></b>
<b name="b2"></b>
<b name="b3"></b>
</a>
The python code
import xml.etree.ElementTree as ET
tree = ET.parse('test.xml')
root = tree.getroot()
root.findall("b[@name='b2' and c]")
The program shows the error:
invalid predicate
But if I use
root.findall("b[@name='b2']") or
root.findall("b[c]")
It works,
(F. Lundh, XPath Support in ElementTree.)
For an ElementTree implementation that supports XPath (1.0), check out LXML: