Given the xml
xmlstr = ''' <myxml> <Description id="10"> <child info="myurl"/> </Description> </myxml>' I'd like to get the id of Description only where child has an attribute of info.
import xml.etree.ElementTree as ET root = ET.fromstring(xmlstr) a = root.find(".//Description/[child/@info]") print(a.attrib) and changing the find to .//Description/[child[@info]]
both return an error of:
SyntaxError: invalid predicate I know that etree only supports a subset of xpath, but this doesn't seem particularly weird - should this work? If so, what have I done wrong?!
Changing the find to .//Description/[child] does work, and returns
{'id': '10'} as expected