Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def clean_empty_nodes(xml_str):
- xml = fromstring(xml_str)
- for child in xml.iter():
- for key, value in child.attrib.items():
- if value == '':
- child.attrib.pop(key)
- if not child.attrib and not child.getchildren():
- child.getparent().remove(child)
- return etree.tostring(xml, pretty_print=True, xml_declaration=True, encoding='UTF-8')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement