[code.view]

[top] / python / PyMOTW / xml / etree / ElementTree / ElementTree_pretty.py

     #!/usr/bin/env python
     # encoding: utf-8
     #
     # Copyright (c) 2010 Doug Hellmann.  All rights reserved.
     #
     """Pretty-print function for ElementTree
     """
     #end_pymotw_header
     
     from xml.etree import ElementTree
     from xml.dom import minidom
     
     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="  ")
     

[top] / python / PyMOTW / xml / etree / ElementTree / ElementTree_pretty.py

contact | logmethods.com