Pretty printing XML in Python

后端 未结 26 2263
一个人的身影
一个人的身影 2020-11-22 02:18

What is the best way (or are the various ways) to pretty print XML in Python?

26条回答
  •  野的像风
    2020-11-22 03:04

    You can use popular external library xmltodict, with unparse and pretty=True you will get best result:

    xmltodict.unparse(
        xmltodict.parse(my_xml), full_document=False, pretty=True)
    

    full_document=False against at the top.

提交回复
热议问题