[XML-SIG] Handling of attribute namespaces

Juergen Hermann Juergen Hermann" <jhe@webde-ag.de
Fri, 31 Aug 2001 14:05:33 +0200


Hi!

Can someone explain why we have, in the following code, the handling 
for NS==None in tag names, but not in attribute names? Smells like a bug.

    def startElementNS(self, name, qname, attrs):
        if name[0] is None:
            name = name[1]
        elif self._current_context[name[0]] is None:
            # default namespace
            name = name[1]
        else:
            name = self._current_context[name[0]] + ":" + name[1]
        self._out.write('<' + name)

        for k,v in self._undeclared_ns_maps:
            if k is None:
                self._out.write(' xmlns="%s"' % v)
            else:
                self._out.write(' xmlns:%s="%s"' % (k,v))
        self._undeclared_ns_maps = []

        for (name, value) in attrs.items():
            name = self._current_context[name[0]] + ":" + name[1]
            self._out.write(' %s=%s' % (name, quoteattr(value)))
        self._out.write('>')

What I get is this:
<?xml version="1.0" encoding="iso-8859-1"?>
<bibliography>
!!!! The following are the args to the __init__ of AttributeNSImpl!
  *** Attrs = {(None, u'id'): u'prescod:1999'}
*** Qnames = {(None, u'id'): u'id'}
<bookTraceback (most recent call last):
  File "tests/test.py", line 38, in ?
    parser.parse(os.path.join(os.path.dirname(sys.argv[0]), "books.xml"))
  File "/netsite/lib/python2.0/_xmlplus/sax/saxutils.py", line 208, in startElementNS
    name = self._current_context[name[0]] + ":" + name[1]
KeyError

When parsing this file:
<?xml version="1.0" encoding="ISO-8859-1"?>

<!DOCTYPE bibliography SYSTEM "books.dtd">

<bibliography>
  <book id="prescod:1999">
    <author>Paul Prescod, Charles F. Goldfarb</author>
    <title>The XML Handbook</title>
    <publisher>Prentice Hall</publisher>
    <year>1999</year>
    <isbn>0130147141</isbn>
    <comment>paperback, 2nd edition, 1074 pages</comment>
  </book>

  <book id="beazley:1999">
    <author>David M. Beazley, Guido Van Rossum</author>
    <title>Python Essential Reference</title>
    <publisher>New Riders Publishing</publisher>
    <year>1999</year>
    <isbn>0735709017</isbn>
    <comment>paperback, 319 p.</comment>
  </book>

  <book id="stumpp:1999">
    <author>Semmy Stumpp</author>
    <title>Projektmanagement mit MS-Project</title>
    <publisher>Markt &amp; Technik</publisher>
    <year>1999</year>
    <isbn>3-82725603-8</isbn>
    <comment>gebundene Ausgabe, 523 S., mit CD-ROM</comment>
  </book>

</bibliography>