← 输入框|bugs.python.org|刷新

➜

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
标题: Add xml pretty print option to ElementTree
类型: enhancement Stage: resolved
Components: Versions: Python 3.8, Python 3.7, Python 3.6, Python 3.5
process
状态: closed Resolution: duplicate
Dependencies: 后续: xml.etree.ElementTree: add feature to prettify XML output
View: 14465
分配给: 抄送列表: eli.bendersky, rhettinger, scoder
优先级: normal 关键字:

Created on 2015-04-02 07:01 by rhettinger, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (2)
msg239879 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) 日期: 2015-04-02 07:01
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:

http://effbot.org/zone/element-lib.htm#prettyprint

The lxml package also provides an API for this purpose:

    print(etree.tostring(root, pretty_print=True))
msg239881 - (view) Author: Stefan Behnel (scoder) * (Python committer) 日期: 2015-04-02 07:08
duplicate of issue 14465
历史
日期 用户 动作 参数
2022-04-11 14:58:15admin修改github: 68035
2018-08-17 15:22:53mcepl修改versions: + Python 3.6, Python 3.7, Python 3.8
2015-04-02 08:20:47serhiy.storchaka修改状态: open -> closed
后续: xml.etree.ElementTree: add feature to prettify XML output
resolution: duplicate
stage: resolved
2015-04-02 07:08:34scoder修改抄送: + rhettinger
消息: + msg239881
2015-04-02 07:02:41rhettinger修改抄送: + scoder, eli.bendersky, - rhettinger
2015-04-02 07:01:50rhettinger创建