📅  最后修改于: 2022-03-11 14:46:43.286000             🧑  作者: Mango
# 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)`