How to ask sax for the file encoding

Diez B. Roggisch deets at nospam.web.de
Wed Oct 4 18:09:50 CEST 2006


Edward K. Ream wrote:

>> [The value of the encoding field] _could_ be retained, but for what
>> purpose?
> 
> I'm asking this question because my app needs it :-)  
> Imo, there is *no* 
> information in any xml file that can be considered irrelvant.  

It sure is! The encoding _is_ irrelevant, in the very moment you get unicode
strings. The order of attributes is irrelevant. There is plenty of
irrelevant whitespace. And so on...

> My app will 
> want to know the original encoding when writing the file.

When your app needs it, whatfor does it need it? If you write out xml again,
use whatever encoding suits you best. If you don't, use the encoding that
the subsequent application or processing step needs.

Diez



More information about the Python-list mailing list