XML and namespaces

and-google at doxdesk.com and-google at doxdesk.com
Mon Dec 19 14:39:29 CET 2005


Uche Ogbuji <uche.ogbuji at gmail.com> wrote:

> Andrew Clover also suggested an overly-legalistic argument that current
> minidom behavior is not a bug.

I stick by my language-law interpretation of spec. DOM 2 Core
specifically disclaims any responsibility for namespace fixup and
advises the application writer to do it themselves if they want to be
sure of the right output. W3C knew they weren't going to get all that
standardised by Level 2 so they left it open for future work - if
minidom claimed to support DOM 3 LS it would be a different matter.

> '<?xml version="1.0" ?>\n<ferh/>'

> (i.e. "ferh" rather than "href"), would you not consider that a minidom
> bug?

It's not a *spec* bug, as no spec that minidom claims to conform to
says anything about serialisation. It's a *minidom* bug in that it
fails to conform to the minimal documentation of the method toxml()
which claims to "Return the XML that the DOM represents as a string" -
the DOM does not represent that XML.

However that doc for toxml() says nothing about being namespace-aware.
XML and XML-with-namespaces both still exist, and for the former class
of document the minidom behaviour is correct.

> The reality is that once the poor user has done:

> element = document.createElementNS("DAV:", "href")

> They are following DOM specification that they have created an element
> in a namespace

It's possible that a namespaced node could also be imported/parsed into
a non-namespace document and then serialised; it's particularly likely
this could happen for scripts processing XHTML.

We shouldn't change the existing behaviour for toxml/writexml because
people may be relying on it. One of the reasons I ended up writing a
replacement was that the behaviour of minidom was not only wrong, but
kept changing under my feet with each version.

However, adding the ability to do fixup on serialisation would indeed
be very welcome - toxmlns() maybe, or toxml(namespaces= True)?

> I'll be sure to emphasize heavily to users that minidom is broken
> with respect to Namespaces and serialization, and that they
> abandon it in favor of third-party tools.

Well yes... there are in any case more fundamental bugs than just
serialisation problems.

Frederik wrote:

> can anyone perhaps dig up a DOM L2 implementation that's not written
> by anyone involved in this thread

<g>

-- 
And Clover
mailto:and at doxdesk.com
http://doxdesk.com/




More information about the Python-list mailing list