Discussion:
[Python-de] (non PyXML) xml.minidom chokes on xml:lang attribute
Christopher Arndt
2003-09-03 18:15:03 UTC
Permalink
Die folgende Mail habe ich auch an die rox-devel Liste geschickt, daher
ist sie auf englisch. Ich bitte, das zu verzeihen und natürlich kann man
auf deutsch antworten!



I played a bit with AppInfo.xml parsing with Python and InfoWin.py from
ROX-Lib2 and encountered the following error when using

from xml.dom import minidom

doc = minidom.parse("AppInfo.xml")

File "<stdin>", line 1, in ?
File "/usr/lib/python2.2/xml/dom/minidom.py", line 962, in parse
return _doparse(pulldom.parse, args, kwargs)
File "/usr/lib/python2.2/xml/dom/minidom.py", line 954, in _doparse
toktype, rootNode = events.getEvent()
File "/usr/lib/python2.2/xml/dom/pulldom.py", line 255, in getEvent
self.parser.feed(buf)
File "/usr/lib/python2.2/xml/sax/expatreader.py", line 144, in feed
self._parser.Parse(data, isFinal)
File "/usr/lib/python2.2/xml/sax/expatreader.py", line 246, in
start_element_ns
prefix = self._ns_stack[-1][apair[0]][-1]
IndexError: list index out of range


This happens only when an Element (e.g. 'About') has a 'xml:lang'
attribute. If I change the namespace prefix to something else (e.g.
'xm'), the error does not occur.

Suspecting pyexpat as the culprit, I installed PyXML 0.8.3 and -- it
worked! (same commands)

As the python library doc states that minidom supports namespaces, and
my "XML in a nutshell" book says a) namespace unaware parses shouldn't
choke when encountering namespase prefixes and b) that the 'xml' prefix
is special and therefore doesn't need a namespace to URI mapping, I'm
stuck with the following questions:

- is this a bug in the Python-included minidom implementation?

- or just a bug in my setup (Mandrake 9.0 with Python 2.2.2 out-of-the-box)?

- or the pyexpat module (in the standard library)?

- or do I overlook something obvious here?

Loading...