I have a xml file and i am searching looking for a specific string in it. when that string is found, i want to return it's parent name. here is my xml:
<context>
<name>AccuCapacityApp</name>
<message>
<source>Capacity</source>
<translation type="unfinished">Kapazität</translation>
</message>
<message>
<source>Charge Level</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Sel (Yes)</source>
<translation type="unfinished">Sel (Ja)</translation>
</message>
<message>
<source>Esc (No)</source>
<translation type="unfinished">Esc (Nein)</translation>
</message>
</context>
I want to search for "unfinished" and return "Capacity" as "source" and "AccuCapacityApp" as "Main".
i tried this but it prints nothing:
import xml.etree.ElementTree as ET
file = "work.xml"
tree = ET.parse(file)
for elem in tree.findall('context/message'):
found = elem.get('unfinished')
print(found.attrib)