Encoding in XML declaration python

后端 未结 1 1771
春和景丽
春和景丽 2021-02-14 20:25

I have created an XML file using python. But the XML declaration has only version info. How can I include encoding with XML declaration like:



        
1条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-14 21:00

    >>> from xml.dom.minidom import Document
    >>> a=Document()
    >>> a.toprettyxml(encoding="utf-8")
    '\n'
    

    or

    >>> a.toxml(encoding="utf-8")
    ''
    

    you can set the encoding for the document.writexml() function in the same way.

    0 讨论(0)
提交回复
热议问题