Created
May 5, 2017 05:16
-
-
Save jmorenoamor/f518f40046d4526b69e22dcb74305073 to your computer and use it in GitHub Desktop.
Prettify and compact an XML string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import xml.dom.minidom | |
def pretty(xml_string): | |
""" Prettify and compact an XML string """ | |
xml_string = xml.dom.minidom.parseString(xml_string).toprettyxml(indent=" ").split('\n') | |
return '\n'.join([line for line in xml_string if line.strip()]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment