Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encoding in XML declaration python

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:

<?xml version="1.0" encoding="UTF-8"?> 
like image 527
Nims Avatar asked Apr 08 '10 04:04

Nims


1 Answers

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

or

>>> a.toxml(encoding="utf-8")
'<?xml version="1.0" encoding="utf-8"?>'

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

like image 101
zoli2k Avatar answered Sep 30 '22 18:09

zoli2k