Skip to content

Instantly share code, notes, and snippets.

@ameenaziz
Created January 5, 2020 02:50
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Embed
What would you like to do?
Remove xml node and containing parent node that has a specific string
import xml.etree.ElementTree as ET
tree = ET.parse('testdata.xml')
root = tree.getroot()
for parentNode in root.findall('ParentXMLTag'):
childNode = parentNode.find('ChildXMLTag').text
search_string = "Lorem Ipsum"
if childNode == search_string:
root.remove(parentNode)
tree.write('cleaned_data_output.xml')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment