elementtree and gbk encoding

Fredrik Lundh fredrik at pythonware.com
Wed Mar 15 11:57:11 CET 2006

Diez B. Roggisch wrote:

>> good advice, but note that an envelope (e.g a HTTP request or response
>> body) may override the encoding in the XML file itself.  if this arrives
>> in a MIME message with the proper charset information, it's perfectly okay
>> to leave out the encoding from the file.
> It might be practical - still, a xml parser _should_ puke on you, ans
> certainly some will (elemnttree not being one of those, I know :))

no, the parser must not to choke on a file for which the encoding has been

for example, the HTTP standard allows the transport layer to recode text/* re-
sources as long as it updates the charset properly, so if you e.g send an XML
document as text/xml and charset=iso-8859-1, the transport layer can recode
that to charset=utf-8, *without* rewriting the XML header.


More information about the Python-list mailing list