I wish to parse an xml file and extract the parent
which contains a
matching a specific text using Python 3.7 & ElementT
Do a (nested) iteration in 2 steps: on sec and then on title. Something like:
for sec in parent.iter("sec"):
for title in sec.iter("title"):
text = title.text
if text and "methods" in text.lower():
print("**title: " + text + " **** sec id: " + sec.get("id", ""))
For more details, check [Python 3.Docs]: xml.etree.ElementTree - The ElementTree XML API.