Created
January 5, 2020 02:50
-
-
Save ameenaziz/941d6988da752f6e2b0de17f9326a149 to your computer and use it in GitHub Desktop.
Remove xml node and containing parent node that has a specific string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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