📜  如何将漂亮的 xml 写入文件 python 代码示例

📅  最后修改于: 2022-03-11 14:46:43.286000             🧑  作者: Mango

代码示例1
# Use lxml as the core library for xml manipulation. 
from lxml import etree

xml_object = etree.tostring(root,
                            pretty_print=True,
                            xml_declaration=True,
                            encoding='UTF-8')

with open("xmlfile.xml", "wb") as writter: # wb - write bytes mode
    writter.write(xml_object)`