[issue9883] minidom: AttributeError: DocumentFragment instance has no attribute 'writexml'

Aubrey Barnard report at bugs.python.org
Fri Sep 17 05:30:46 CEST 2010

New submission from Aubrey Barnard <aubrey.f.barnard at gmail.com>:

Writing a document fragment doesn't work because the 'writexml' method is not implemented.

I would like to be able to write out document fragments as XML text, but this functionality is not implemented. Here are the reasons why I think this functionality should be implemented.

1. DOM Level 1 describes a document fragment as a lightweight document. I can write a document as XML text so why not a document fragment?

2. This would be very easy to implement, basically just the child processing loop from Element.writexml:
for node in self.childNodes:

3. Document fragments are often returned as intermediate results in XML building. The best way I can think of to unit test these results is by writing the document fragment as XML text and comparing to an existing string. (Comparing two document fragments is not guaranteed to work.)

4. Implementing an XML editor on top of minidom would require this functionality, e.g. display a piece of cut XML.

I realize that writing document fragments as XML text is not a common or "core" operation, but it makes sense in the above four cases and perhaps other cases as well. Therefore, to me, implementing this functionality is less a question of "Why?" and more a question of "Why not?"

I will be glad to add any other information as requested.

components: XML
messages: 116644
nosy: Aubrey.Barnard
priority: normal
severity: normal
status: open
title: minidom: AttributeError: DocumentFragment instance has no attribute 'writexml'
type: behavior
versions: Python 2.6

Python tracker <report at bugs.python.org>

More information about the Python-bugs-list mailing list