xml.dom.minidom losing the XML document type attribute

Stefan Behnel stefan_ml at behnel.de
Thu Jun 11 12:54:51 CEST 2009


Johannes Bauer wrote:
> Stefan Behnel schrieb:
>> Johannes Bauer wrote:
>>> when I read in a XML document with the xml.dom.minidom parser and write
>>> it out again, an attribute is lost:
>>>
>>> Input:
>>>
>>> <?xml version="1.0" encoding="utf-8" ?>
>>> [...]
>>>
>>> Output:
>>> <?xml version="1.0" ?>
>>>
>>> How can I fix this?
>> You don't have to. UTF-8 is the default encoding, so the two lines above
>> are equivalent.
> 
> Can I somehow force Python to generate it anyways?

Did you try passing encoding='UTF-8' on serialisation?


> I have software which
> complains if an explicit encoding is missing...

Well, to parse XML, it's best to use an XML parser. ;)

Stefan



More information about the Python-list mailing list