def indent_xml(xml_string):
    if isinstance(xml_string, unicode):
        xml_string = xml_string.encode('utf-8')
    return minidom.parseString(xml_string).toprettyxml()
Takes an xml string and returns an indented and properly tabbed version of the string
dataset/ETHPy150Open dimagi/commcare-hq/corehq/util/xml_utils.py/indent_xml