[xml] Python/libxml2/Unicode problem



Greetings,

I'm in the process of porting my python app. to libxml2, and have now run into a problem with Unicode.

I'm creating a DOM ducument piece-by-piece, something like:

elem = libxml2.newNode("submit")
elem.addContent(somestring)

The addContent gives me an Python exception:

 ....
  File "C:\Local\Python23\Lib\site-packages\libxml2.py", line 2751, in addContent
    libxml2mod.xmlNodeAddContent(self._o, content)
UnicodeEncodeError: 'ascii' codec can't encode characters in position 37-39: ordinal not in range(128)

The string I'm sending in is the following:

u'http://sim_cps2/WIG20/1454.asp?VAR01=\\xf1\\xfc\\xe0&VAR02=$(VAR1:sms-default)_$(VAR2:binary)'

Apparently I does not like the characters that falls outside the Ascii subset:

00F1 ñ LATIN SMALL LETTER N WITH TILDE
00FC ü LATIN SMALL LETTER U WITH DIAERESIS
00E0 à LATIN SMALL LETTER A WITH GRAVE

What is going on here? Why is the python-binding trying to encode into ascii at all? Or is it just me 
misunderstanding something here...

Gratefull for any answer.

Regards
/Örjan

BTW: libxml2 is really a wonderfull piece of software!!



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]