minidom
Bernhard Trummer
bernhard.trummer at divis.at
Fri Sep 14 05:36:45 EDT 2001
hi.
I am new in python (and also xml) - and I have (maybe - I hope) a silly
problem:
I use the XML only to read (and parse) an input file (I do not create XML
files!)
My XML file has germen letters like äüö (- thats the problem).
On running the python-script I get a Unicode Error in python!
(with ASCII chars up to 127 it works fine!)
What can I do?
thanx
Bernhard
My XML-file looks like:
----------------------------------------------------------------
<?xml version="1.0" encoding ="ISO-8859-1"?>
<messages version="102">
<message>
<TXT>Eisenstadt: Europaplatz, zwischen Bürgerspitalgasse und
Kurzwiesenweg: </TXT>
</message>
<message>
<TXT>A2 Autobahn:</TXT>
</message>
...
</messages>
----------------------------------------------------------------
The error message:
----------------------------------------------------------------
File "F:\\Scripts\XMLTest2.py", line 54, in handlePoint
print "<li>%s</li>" % getText(point.childNodes)
UnicodeError: ASCII encoding error: ordinal not in range(128)
----------------------------------------------------------------
The phython code (where it crashes)
----------------------------------------------------------------
def handlePoint(point):
print "<li>%s</li>" % unicode(getText(point.childNodes))
def getText(nodelist):
rc = ""
for node in nodelist:
if node.nodeType == node.TEXT_NODE:
rc = rc + node.data
return rc
----------------------------------------------------------------
More information about the Python-list
mailing list