minidom questions

Martin v. Löwis martin at v.loewis.de
Thu Nov 20 15:10:39 EST 2003


xtian at toysinabag.com (xtian) writes:

> Is this a bug? 

It's a bug. The attribute value should be an empty string.

> I can see how to get what I want by
> replacing Element.writexml with one that checks to see whether all the
> childNodes are text. Is there a better way to do this?

Replacing methods in classes is certainly not a good thing.

What you *really* should do is to write your own traversal function
which does the saving of the document. For example, you could use the
PyXML xml.dom.ext.Printer module, and subclass the PrinterVisitor
(if you don't want to write the traversal from scratch).

If you really think you should only replace a single toxml
implementation on elements, you could use extended elements. To do so,
inherit from the Element class, redefining toxml, from the Document
class, redefining createElement, and from the DOMImplementation
class, redefining createDocument.

HTH,
Martin




More information about the Python-list mailing list