XML Declaration standalone=“yes” lxml

前端 未结 5 1204
暗喜
暗喜 2020-12-20 13:01

I have an xml I am parsing, making some changes and saving out to a new file. It has the declaration

5条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-20 13:29

    You can pass standalone keyword argument to tostring():

    etree.tostring(tree, pretty_print = True, xml_declaration = True, encoding='UTF-8', standalone=True)
    

提交回复
热议问题