2 ElementTree helper functions
4 def indent(elem, level=0):
6 reformat an element tree to be 'pretty' (indented)
10 if not elem.text or not elem.text.strip():
13 indent(child, level+1)
14 # we don't want the closing tag indented too far
16 if not elem.tail or not elem.tail.strip():
19 if level and (not elem.tail or not elem.tail.strip()):
22 def flatten(elem, include_tail=0):
24 Extract the text from an element tree
25 (AKA extract the text that not part of XML tags)
27 text = elem.text or ""
30 if include_tail and elem.tail: text += elem.tail