def pretty_xml_tree(elem, level=0, indent=u'  '):
 if (((not elem.text) and (len(elem) > 0)) or (elem.text and isspace(elem.text))):
  elem.text = (u'\n' + (indent * (level + 1)))
 for (i, child) in enumerate(elem):
  pretty_xml_tree(child, level=(level + 1), indent=indent)
  if ((not child.tail) or isspace(child.tail)):
   l = (level + 1)
   if (i == (len(elem) - 1)):
    l -= 1
   child.tail = (u'\n' + (indent * l))

def pretty_xml_tree ( elem , level = 0 , indent = u'  ' ) : if ( ( ( not elem . text ) and ( len ( elem ) > 0 ) ) or ( elem . text and isspace ( elem . text ) ) ) : elem . text = ( u'\n' + ( indent * ( level + 1 ) ) ) for ( i , child ) in enumerate ( elem ) : pretty_xml_tree ( child , level = ( level + 1 ) , indent = indent ) if ( ( not child . tail ) or isspace ( child . tail ) ) : l = ( level + 1 ) if ( i == ( len ( elem ) - 1 ) ) : l -= 1 child . tail = ( u'\n' + ( indent * l ) )
xml beautifier .