Re: unicode problems in elementtree
David Stanek <[email protected]>
| Newsgroups | gmane.comp.python.xml |
|---|---|
| Message-ID | <[email protected]> |
On Fri, May 26, 2006 at 09:22:41PM +0100, Bryan Lawrence wrote:
>
> Does elementtree and/or expat need to know the encoding to get this right?
> (which may be a problem coz this could be from anyone's document in any
> encoding ...)
>
I think you will have to tell elementtree what encoding your XML is
in. Otherwise how would it know? I am sure there is a better way,
but I have seen people try to guess encodings like:
# untested and from my bad memory :-)
encodings = ['utf-8', 'utf-16',i 'iso-8859-1',]
for encoding in encodings:
try:
unicode(s, encoding)
except UnicodeError:
pass
else:
break
The encodings list would be a list of common encodings that you may
expect. Again there must be a better way to do this... I would
suggest that you try to set a standard for encodings.
David Stanek
--
http://www.traceback.org
GPG keyID #6272EDAF on http://pgp.mit.edu
Key fingerprint = 8BAA 7E11 8856 E148 6833 655A 92E2 3E00 6272 EDAF
_______________________________________________
XML-SIG maillist - [email protected]
http://mail.python.org/mailman/listinfo/xml-sig
signature.asc
(application/pgp-signature, 189 B)
-----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.2 (GNU/Linux) iD8DBQFEd4J1kuI+AGJy7a8RAiwrAJ9Rjnqb3ECdQSUN+AdtGcGE7oOD/QCfToTs ZS650h/VYPauw5U/3D4ebL0= =pUOA -----END PGP SIGNATURE-----