XML and namespaces

uche.ogbuji at gmail.com uche.ogbuji at gmail.com
Fri Dec 2 18:26:07 EST 2005


Alan Kennedy:
"""
> Oh no.  That only means that namespace declaration attributes are not
> created in the DOM data structure.  However, output has to fix up
> namespaces in .namespaceURI properties as well as directly asserted
> "xmlns" attributes.  It would be silly for DOM to produce malformed
> XML+XMLNS, and of course it is not meant to.  The minidom behavior
> needs fixing, badly.

My interpretation of namespace nodes is that the application is
responsible for creating whatever namespace declaration attribute nodes
are required, on the DOM tree.

DOM should not have to imply any attributes on output.
"""

I'm sorry but you're wrong on this.  First of all, DOM L2 (the level
minidom targets) does not have the concept of "namespace nodes".
That's XPath.  DOM supports two ways of expressing namespace
information.  The first way is through the node properties
.namespaceURI, .prefix (for the QName) and .localName.  It *also*
supports literal namespace declaration atrributes (the NSDecl
attributes themselves must have a namespace of
"http://www.w3.org/2000/xmlns/").  As if this is not confusing enough
the Level 1 propoerty .nodeName must provide the QName, redundantly.

As a result, you have to perform fix-up to merge properties with
explicit NSDEcl attributes in order to serialize.  If it does not do
so, it is losing all the information in namespace properties, and the
resulting output is not the same document that is represented in the
DOM.

Believe me, I've spent many weary hours with all these issues, and
implemented code to deal with the mess multiple times, and I know it
all too painfully well.  I wrote Amara largely because I got
irrecoverably sick of DOM's idiosyncracies.

Andrew, for this reason I probably take the initiative to work up a
patch for the issue.  I'll do what I can to get to it tomorrow.  If you
help me with code review and maybe writing some tests, that would be a
huge help.

--
Uche Ogbuji                               Fourthought, Inc.
http://uche.ogbuji.net                    http://fourthought.com
http://copia.ogbuji.net                   http://4Suite.org
Articles: http://uche.ogbuji.net/tech/publications/




More information about the Python-list mailing list