Skip to content

Instantly share code, notes, and snippets.

@jefftriplett
Created October 30, 2012 14:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jefftriplett/3980637 to your computer and use it in GitHub Desktop.
Save jefftriplett/3980637 to your computer and use it in GitHub Desktop.
Return a pretty-printed XML string for the Element.
from xml.dom import minidom
from xml.etree import ElementTree
def prettify(elem):
"""
Return a pretty-printed XML string for the Element.
"""
rough_string = ElementTree.tostring(elem, 'utf-8')
reparsed = minidom.parseString(rough_string)
return reparsed.toprettyxml(indent=' ')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment