[XML-SIG] xmlns='' and DOM regression?
Stéphane Bidoul
stephane.bidoul@softwareag.com
Wed, 12 Dec 2001 17:01:58 +0100
Hi!
It seems to me that the latest commits to
dom/ext/reader/sax2.py introduced a slight regression
in the handling of xmlns=''.
Here's the script:
import xml.dom.ext.reader.Sax2
xmls = "<test xmlns=''>data</test>"
doc = xml.dom.ext.reader.Sax2.FromXml(xmls)
And the stack trace
Traceback (most recent call last):
File "sbi.py", line 3, in ?
doc = xml.dom.ext.reader.Sax2.FromXml(xmls)
File "c:\soft\python21\_xmlplus\dom\ext\reader\Sax2.py", line 389, in FromXml
saxHandlerClass, parser)
File "c:\soft\python21\_xmlplus\dom\ext\reader\Sax2.py", line 382, in FromXmlStream
return reader.fromStream(stream, ownerDocument)
File "c:\soft\python21\_xmlplus\dom\ext\reader\Sax2.py", line 368, in fromStream
self.parser.parse(s)
File "c:\soft\python21\_xmlplus\sax\expatreader.py", line 58, in parse
xmlreader.IncrementalParser.parse(self, source)
File "c:\soft\python21\_xmlplus\sax\xmlreader.py", line 123, in parse
self.feed(buffer)
File "c:\soft\python21\_xmlplus\sax\expatreader.py", line 143, in feed
self._parser.Parse(data, isFinal)
File "c:\soft\python21\_xmlplus\sax\expatreader.py", line 217, in start_element
self._cont_handler.startElement(name, AttributesImpl(attrs))
File "c:\soft\python21\_xmlplus\dom\ext\reader\Sax2.py", line 64, in startElement
local + ':' + prefix)
TypeError: cannot add type "None" to string
After a quick look at the code I'd suggest the following patch
(but the real problem may be elsewhere).
Index: Sax2.py
===================================================================
RCS file: /cvsroot/pyxml/xml/xml/dom/ext/reader/Sax2.py,v
retrieving revision 1.19
diff -c -5 -r1.19 Sax2.py
*** Sax2.py 2001/12/06 16:02:44 1.19
--- Sax2.py 2001/12/12 15:58:39
***************
*** 59,69 ****
for curr_attrib_key,curr_attrib_value in attribs.items():
(prefix, local) = SplitQName(curr_attrib_key)
if local == 'xmlns':
namespace = XMLNS_NAMESPACE
attr = self._ownerDoc.createAttributeNS(namespace,
! local + ':' + prefix)
else:
namespace = prefix and self._namespaces.get(prefix, None) or None
attr = self._ownerDoc.createAttributeNS(namespace,
(prefix and prefix + ':' + local) or local)
attr.value = curr_attrib_value
--- 59,69 ----
for curr_attrib_key,curr_attrib_value in attribs.items():
(prefix, local) = SplitQName(curr_attrib_key)
if local == 'xmlns':
namespace = XMLNS_NAMESPACE
attr = self._ownerDoc.createAttributeNS(namespace,
! (prefix and local + ':' + prefix) or local)
else:
namespace = prefix and self._namespaces.get(prefix, None) or None
attr = self._ownerDoc.createAttributeNS(namespace,
(prefix and prefix + ':' + local) or local)
attr.value = curr_attrib_value
Can someone have a quick look at this?
Or, if the issue is more difficult to solve,
I can post this as a bug on SF .
-Stephane