/ Published in: Python
URL: http://effbot.org/zone/element-lib.htm
This is a custom function in the elementree documenation, copied here for reference.
Expand |
Embed | Plain Text
def indent(elem, level=0): i = "\n" + level*" " if len(elem): if not elem.text or not elem.text.strip(): elem.text = i + " " if not elem.tail or not elem.tail.strip(): elem.tail = i for elem in elem: indent(elem, level+1) if not elem.tail or not elem.tail.strip(): elem.tail = i else: if level and (not elem.tail or not elem.tail.strip()): elem.tail = i def printxml(xml): import xml.etree.ElementTree as et elem = et.fromstring(xml) indent(elem) print et.tostring(elem)
You need to login to post a comment.
