elementtree and gbk encoding

Fredrik Lundh fredrik at pythonware.com
Wed Mar 15 06:48:58 CET 2006

Diez B. Roggisch wrote:

>   2) your xml is _not_ well-formed, as it doesn't contain a xml-header!
> You need ask these guys to deliver the xml with header. Of course for
> now it is ok to just prepend the text with something like <?xml
> version="1.0" encoding="gbk"?>. But I'd still request them to deliver it
> with that header - otherwise it is _not_ XML, but just something that
> happens to look similar and doesn't guarantee to be well-formed and thus
> can be safely fed to a parser.

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.


More information about the Python-list mailing list