From jens.dobberthin at noonox.com Thu Nov 20 08:49:28 2003 From: jens.dobberthin at noonox.com (Jens Dobberthin) Date: Sun Aug 10 16:54:54 2008 Subject: [Zope-xml] Unicode and libxml2 Message-ID: <1069336168.2285.35.camel@snoopy> 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. From Yves.Bastide at irisa.fr Thu Nov 20 08:51:40 2003 From: Yves.Bastide at irisa.fr (Yves Bastide) Date: Sun Aug 10 16:54:54 2008 Subject: [Zope-xml] Unicode and libxml2 In-Reply-To: <1069336168.2285.35.camel@snoopy> References: <1069336168.2285.35.camel@snoopy> Message-ID: <3FBCC6EC.2050207@irisa.fr> 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? Can't you just use utf-8 all along, instead of latin1? > > Thanks in advance, > Jens. yves From jensd at media-meter.de Thu Nov 20 11:32:12 2003 From: jensd at media-meter.de (Jens Dobberthin) Date: Sun Aug 10 16:54:54 2008 Subject: [Zope-xml] Unicode and libxml2 In-Reply-To: <3FBCC6EC.2050207@irisa.fr> References: <1069336168.2285.35.camel@snoopy> <3FBCC6EC.2050207@irisa.fr> Message-ID: <1069345932.2371.45.camel@snoopy> > > 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? > > Can't you just use utf-8 all along, instead of latin1? But than I get something like '/xc4' on my website. Maybe it works fine if I set the charset of of html page to utf-8, but which encoding format will all the fields of my web from have? Jens. From Yves.Bastide at irisa.fr Thu Nov 20 12:30:36 2003 From: Yves.Bastide at irisa.fr (Yves Bastide) Date: Sun Aug 10 16:54:54 2008 Subject: [Zope-xml] Unicode and libxml2 In-Reply-To: <1069345932.2371.45.camel@snoopy> References: <1069336168.2285.35.camel@snoopy> <3FBCC6EC.2050207@irisa.fr> <1069345932.2371.45.camel@snoopy> Message-ID: <3FBCFA3C.5050903@irisa.fr> Jens Dobberthin wrote: >>>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? >> >>Can't you just use utf-8 all along, instead of latin1? > > > But than I get something like '/xc4' on my website. Maybe it works fine > if I set the charset of of html page to utf-8, but which encoding format > will all the fields of my web from have? utf-8, I guess :) I'm using [...] e.g. in connection with a PostgreSQL Unicode daatabase, and everything's working. > > Jens. yves From jens.dobberthin at noonox.com Thu Nov 20 14:17:50 2003 From: jens.dobberthin at noonox.com (Jens Dobberthin) Date: Sun Aug 10 16:54:54 2008 Subject: [Zope-xml] Unicode and libxml2 In-Reply-To: <3FBCFA3C.5050903@irisa.fr> References: <1069336168.2285.35.camel@snoopy> <3FBCC6EC.2050207@irisa.fr> <1069345932.2371.45.camel@snoopy> <3FBCFA3C.5050903@irisa.fr> Message-ID: <1069355870.2373.64.camel@snoopy> Salut Yves, I tried to use xml documents as you have recommended but got the following error by Zope (2.6.2): über Zope also spits out on my console: [jens@snoopy webelias]$ I've installed the latest version of PyXML (0.8.3 - I don't if I need it). Anyway it seems that zope's xml parser crashs. The same file viewed directly by Mozilla (and not through zope) works fine. Another funny thing is that if I create a PageTemplate with the content above within the ZODB (the one above is visible through DirectoryView of the CMF Product) it works fine, too. Where do you store your templates? Greetings, Jens. Am Don, 2003-11-20 um 18.30 schrieb Yves Bastide: > Jens Dobberthin wrote: > >>>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? > >> > >>Can't you just use utf-8 all along, instead of latin1? > > > > > > But than I get something like '/xc4' on my website. Maybe it works fine > > if I set the charset of of html page to utf-8, but which encoding format > > will all the fields of my web from have? > > utf-8, I guess :) > I'm using > > "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> > > [...] > > > e.g. in connection with a PostgreSQL Unicode daatabase, and everything's > working. > > > > > Jens. > > yves > > From jens.dobberthin at noonox.com Wed Nov 26 05:58:12 2003 From: jens.dobberthin at noonox.com (Jens Dobberthin) Date: Sun Aug 10 16:54:54 2008 Subject: [Zope-xml] writing xml to a buffer (using libxml) Message-ID: <1069844291.2318.9.camel@snoopy> Salut, is there any way to write a xml tree to a buffer. I tried report = StringIO.StringIO() reportDoc.saveFormatFileTo(report, 'ISO-8859-1', 1) but that doesn't work. The error code is Error Type: AttributeError Error Value: _o Any ideas? Thanks in advance! Jens. From bkc at murkworks.com Wed Nov 26 14:23:08 2003 From: bkc at murkworks.com (Brad Clements) Date: Sun Aug 10 16:54:54 2008 Subject: [Zope-xml] writing xml to a buffer (using libxml) In-Reply-To: <1069844291.2318.9.camel@snoopy> Message-ID: <3FC4AAB9.27145.293855B9@localhost> On 26 Nov 2003 at 11:58, Jens Dobberthin wrote: > is there any way to write a xml tree to a buffer. I tried > > report = StringIO.StringIO() > reportDoc.saveFormatFileTo(report, 'ISO-8859-1', 1) > > but that doesn't work. The error code is > .. styleDoc = libxml2.parseDoc(styleSheetText) style = libxslt.parseStylesheetDoc(styleDoc) doc = libxml2.parseDoc(srcXML) result = style.applyStylesheet(doc,stylesheetArgs) # can insert stylesheet args here res = style.saveResultToString(result) style.freeStylesheet() doc.freeDoc() result.freeDoc() return res Or .. return StringIO.StringIO(res) if you need a file-like object as the result. -- Brad Clements, bkc@murkworks.com (315)268-1000 http://www.murkworks.com (315)268-9812 Fax http://www.wecanstopspam.org/ AOL-IM: BKClements From jensd at media-meter.de Thu Nov 27 07:16:44 2003 From: jensd at media-meter.de (Jens Dobberthin) Date: Sun Aug 10 16:54:54 2008 Subject: [Zope-xml] writing xml to a buffer (using libxml) In-Reply-To: <3FC4AAB9.27145.293855B9@localhost> References: <3FC4AAB9.27145.293855B9@localhost> Message-ID: <1069935404.2311.3.camel@snoopy> Hi, thanks for your answer. Daniel from xml@gnome.org suggested >-- use report.serialize() to generate a string. see python/tests/serialize.py example in the source. <-- and it works fine for me. Jens. Am Mit, 2003-11-26 um 20.23 schrieb Brad Clements: > On 26 Nov 2003 at 11:58, Jens Dobberthin wrote: > > > is there any way to write a xml tree to a buffer. I tried > > > > report = StringIO.StringIO() > > reportDoc.saveFormatFileTo(report, 'ISO-8859-1', 1) > > > > but that doesn't work. The error code is > > > > > .. > > styleDoc = libxml2.parseDoc(styleSheetText) > style = libxslt.parseStylesheetDoc(styleDoc) > > doc = libxml2.parseDoc(srcXML) > result = style.applyStylesheet(doc,stylesheetArgs) # can insert stylesheet args here > res = style.saveResultToString(result) > style.freeStylesheet() > doc.freeDoc() > result.freeDoc() > return res > > Or .. > > return StringIO.StringIO(res) > > if you need a file-like object as the result.