[XML-SIG] xml namespace prefix and xml.sax.saxutils.XMLGenerator

Uche Ogbuji uche.ogbuji@fourthought.com
Sat, 08 Mar 2003 18:35:17 -0700


> Hi there,
> 
> I'm using xml.sax.saxutils.XMLGenerator to generate XML from sax
> events automatically, and I think I've discovered a bug.

[SNIP]

For my aprt, I'm quite familiar ith all the specifications from which you 
quoted, but I saw no actual code in your reportthat demonstrates the problem.  
I couldn't reconstruct it from your description.

Do you mean that you create an attributeNSImpl object containing 
{http://www.w3.org/XML/1998/namespace}lang (James Clark notation) and that you 
got a traceback as a result?  If so, then that is a bug, but I'm just guessing 
you mean the above.  I'd like to see some tet code and the error it produces.


> The generator works fine for 'xmlns', but it doesn't seem to handle 'xml'
> properly. What should be the case if I understand this right is that the
> 'xml' namespace is always declared (and thus does not get a special
> xmlns declaration). The XMLGenerator and perhaps other code does not
> recognize the 'xml' prefix however, and barfs over it when generating 
> startElementNS().
> 
> Trying to introduce it by using startPrefixMapping() fails, as then
> the generator automatically will add an explicit definition to the document
> element (xmlns:xml="http://www.w3.org/XML/1998/namespace"), which shouldn't
> happen.

It is perfectly correct to explicitly declare the xml prefix, as long as it is 
declared to the http://www.w3.org/XML/1998/namespace namespace.  Of course it 
is *convenient* not to generate this declaration, since it's not needed.


> The fix seems to be as following. Change line 221 or thereabouts from:
> 
>         self._ns_contexts = [{}] # contains uri -> prefix dicts
> 
> into this:
> 
>         # contains uri -> prefix dicts 
>         self._ns_contexts = [{'http://www.w3.org/XML/1998/namespace': 'xml'}]
> 
> If this is deemed to be a good fix I can check this one in myself. I wonder
> though if there would be any other problems with 'xml:' in sax handlers I'm less
> familiar with (reading it in appears to work fine). Anyone?

Thanks for finding a fix, but I'd like to be sure I understand the bug repro 
case before I coul decided whether this is a needed ix.


-- 
Uche Ogbuji                                    Fourthought, Inc.
http://uche.ogbuji.net    http://4Suite.org    http://fourthought.com
Universal Business Language (UBL) - http://www-106.ibm.com/developerworks/xml/library/x-think16.html
EXSLT by example - http://www-106.ibm.com/developerworks/library/x-exslt.html
The worry about program wizards - http://www.adtmag.com/article.asp?id=7238
Use rdf:about and rdf:ID effectively in RDF/XML - http://www-106.ibm.com/developerworks/xml/library/x-tiprdfai.html
Keep context straight in XSLT - http://www-106.ibm.com/developerworks/xml/library/x-tipcurrent.html
Python Generators + DOM - http://www.xml.com/pub/a/2003/01/08/py-xml.html
Simple XML Processing With elementtree - http://www.xml.com/pub/a/2003/02/12/py-xml.html