Clarification on XML parsing & namespaces (xml.dom.minidom)

Uche Ogbuji uche at
Thu Jan 27 22:19:25 EST 2005

Greg Wogan-Browne wrote:
> I am having some trouble figuring out what is going on here - is this
> bug, or correct behaviour? Basically, when I create an XML document
> a namespace using xml.dom.minidom.parse() or parseString(), the
> namespace exists as an xmlns attribute in the DOM (fair enough, as
> in the original source document). However, if I use the DOM
> implementation to create an identical document with a namespace, the
> xmlns attribute is not present.
> This mainly affects me when I go to print out the document again
> Document.toxml(), as the xmlns attribute is not printed for documents
> create dynamically, and therefore XSLT does not kick in (I'm using an

> external processor).
> Any thoughts on this would be appreciated. Should I file a bug on

It's odd behavior, but I think it's a stretch to call it a bug.  You
problem is that you're mixing namespaced documents with the
non-namespace DOM API.  That means trouble and such odd quirks every

Use getAttributeNS, createElementNS, setAttributeNS, etc. rather than
getAttribute, createElement, setAttribute, etc.

Uche Ogbuji                                    Fourthought, Inc.
Use CSS to display XML -
Introducing the Amara XML Toolkit -
Be humble, not imperial (in design) - 1.0 -
Manage XML collections with XAPI -
Default and error handling in XSLT lookup tables -
Packaging XSLT lookup tables as EXSLT functions -

More information about the Python-list mailing list