def prettify(elem):
    """Return a pretty-printed XML string for the Element.
    """
rough_string = ElementTree.tostring(elem, 'utf-8')
use xml.etree.elementtree to write out nicely formatted xml files