[Zope] Unicode and libxml2

Bernd Dorn zope-mailinglist at mopa.at
Thu Nov 20 11:27:30 EST 2003


Jens Dobberthin wrote:

> Salut,
> 
> I'm using Zope2.6 (Python2.1) and libxml2 and got some trouble with
> unicode. I'm parsing a xml document and write out the content of the
> nodes with:
> 
> def utf_to_latin(content):
>   """Converts an string in utf-8 to latin 1."""
>   return unicode(content,'utf-8').encode('iso-8859-1')
> 
> That works fine, since it prints nice the German "Umlauts". Now I made
> some changes via a web form and want to store back the new content. When
> I call 
> 
> reportDoc.saveFormatFileEnc('-', 'ISO-8859-1', 1)
> 
> it fails. Probably because the nodes of the xml tree do not contain
> UTF-8 strings. So how to convert the data I've got from the web form
> into UTF-8? 
> 
> Thanks in advance,
> Jens.
> 
> 
> 
> _______________________________________________
> Zope maillist  -  Zope at zope.org
> http://mail.zope.org/mailman/listinfo/zope
> **   No cross posts or HTML encoding!  **
> (Related lists - 
>  http://mail.zope.org/mailman/listinfo/zope-announce
>  http://mail.zope.org/mailman/listinfo/zope-dev )

you have to set the right encoding in the form page, via the response 
object and/or meta tags

browsers are supposed to send form results in the encoding of the form page

i dont know if it is available prior zope 2.7, but you can specify the 
encoding when using ustring and utext in the form field names, zope then 
  automatically decodes the values and gives u a unicode.

eg: <input name="title:ustring">

greetings, bernd






More information about the Zope mailing list