[New-bugs-announce] [issue23847] Add xml pretty print option to ElementTree

Raymond Hettinger report at bugs.python.org
Thu Apr 2 09:01:50 CEST 2015

New submission from Raymond Hettinger:

The xml.dom.minidom package has as a xml.toprettyxml() function that has the problem of altering the whitespace of the text of elements.   The ElementTree module needs a prettify option that works better, perhaps something based of Effbot's code at:


The lxml package also provides an API for this purpose:

    print(etree.tostring(root, pretty_print=True))

messages: 239879
nosy: rhettinger
priority: normal
severity: normal
status: open
title: Add xml pretty print option to ElementTree
type: enhancement
versions: Python 3.5

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list