Aug-20-2018, 05:08 PM
Below is the whole code that i'm using as of now.
import xml.etree.ElementTree as ET tree = ET.parse("xml_test.txt") root = tree.getroot() for elem in root.iter('MsgHeader'): Deal = root.find("./MsgHeader/Deal") empty = root.find("./MsgHeader/Deal/Attribute/[Value='']") Deal.remove(empty) print(ET.tostring(root, encoding='utf8').decode('utf8'))The use case is that at some places in the sample XML, the <Value> tag is empty. So every-time we encounter a tag like this, we need to remove the corresponding <Attribute> tag from the xml itself.