Python beginner needs help filtering .xml files. I've been trying with xml.etree.ElementTree having little success.
The xml looks like this:
<ClientData>
<Report>
<ReportHost>
<ReportItem pluginID="11111">
Ipsum lorem etc leviosa!
</ReportItem>
</ReportHost>
<ReportHost>
<ReportItem pluginID="22222">
Sed ut perspiciatis unde omnis iste
</ReportItem>
</ReportHost>
</Report>
</ClientData>
If the ReportItem.pluginID matches an item on a blacklist, I would like to remove the entire element (ReportItem) along with its children, then write the filtered .xml. Thanks!
Edit - Here's what I have so far but I'm not sure how to get it to work with this level of nesting:
from xml.etree.ElementTree import ElementTree
tree = ElementTree()
# Test input
tree.parse("test.xml")
for node in tree.findall('ReportItem'):
if tag.attrib['pluginID']=='11111':
tree.remove(node)
tree.write('test_out.xml')