XML and namespaces

uche.ogbuji at gmail.com uche.ogbuji at gmail.com
Mon Dec 5 21:19:01 EST 2005

Wilfredo Sánchez Vega:
   I'm having some issues around namespace handling with XML:

        >>> document = xml.dom.minidom.Document()
        >>> element = document.createElementNS("DAV:", "href")
        >>> document.appendChild(element)
        <DOM Element: href at 0x1443e68>
        >>> document.toxml()
        '<?xml version="1.0" ?>\n<href/>'

   Note that the namespace wasn't emitted.  If I have PyXML,
xml.dom.ext.Print does emit the namespace:

        >>> xml.dom.ext.Print(document)
        <?xml version='1.0' encoding='UTF-8'?><href xmlns='DAV:'/>

   Is that a limitation in toxml(), or is there an option to make it
include namespaces?

Getting back to the OP:

PyXML's xml.dom.ext.Print does get things right, and based on
discussion in this thread, the only way you can serialize correctly is
to use that add-on with minidom, or to use a third party, properly
Namespaces-aware tool such as 4Suite (there are others as well).

Good luck.

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