我已经使用python创建了一个XML文件。但是XML声明只有版本信息。如何在XML声明中包含编码,如:
<?xml version="1.0" encoding="UTF-8"?>
发布于 2010-04-08 05:13:25
>>> from xml.dom.minidom import Document
>>> a=Document()
>>> a.toprettyxml(encoding="utf-8")
'<?xml version="1.0" encoding="utf-8"?>\n'
或
>>> a.toxml(encoding="utf-8")
'<?xml version="1.0" encoding="utf-8"?>'
您可以用同样的方法设置document.writexml()
函数的编码。
https://stackoverflow.com/questions/2597622
复制相似问题