This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: minidom: AttributeError: DocumentFragment instance has no attribute 'writexml'
Type: enhancement Stage: patch review
Components: XML Versions: Python 3.8
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Aubrey.Barnard, cheryl.sabella, fdrake, miss-islington, scoder, serhiy.storchaka
Priority: normal Keywords: patch

Created on 2010-09-17 03:30 by Aubrey.Barnard, last changed 2022-04-11 14:57 by admin.

Pull Requests
URL Status Linked Edit
PR 1726 closed arp11, 2017-05-22 20:41
PR 1745 closed arp11, 2017-05-23 00:30
PR 12677 merged scoder, 2019-04-03 17:47
PR 12709 closed miss-islington, 2019-04-06 16:58
PR 12712 merged miss-islington, 2019-04-07 05:15
Messages (8)
msg116644 - (view) Author: Aubrey Barnard (Aubrey.Barnard) Date: 2010-09-17 03:30
Summary:
Writing a document fragment doesn't work because the 'writexml' method is not implemented.

Problem:
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:
    node.writexml(writer,indent+addindent,addindent,newl)

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.
msg228270 - (view) Author: Mark Lawrence (BreamoreBoy) * Date: 2014-10-02 22:27
Can someone please confirm that my assessment of this as an enhancement is correct, thanks.
msg294218 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2017-05-23 04:06
I agree that writexml should be available for document fragments.

I doubt the additional level of indentation should be added, as you've included in point 2.
msg339377 - (view) Author: Fred Drake (fdrake) (Python committer) Date: 2019-04-03 04:29
Updated target to Python 3.8, since this has aged a bit.
msg339405 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2019-04-03 17:47
Seems like a reasonable request to me, even if it hasn't been touched or re-requested for years.

Funny enough, DocumentFragment is currently documented as "not implemented" (as for Entity, Notation, CDATASection, CharacterData, DOMImplementation, DocumentType). I'll add a PR to clean those up.

https://docs.python.org/3/library/xml.dom.minidom.html#minidom-and-the-dom-standard
msg339539 - (view) Author: Serhiy Storchaka (serhiy.storchaka) * (Python committer) Date: 2019-04-06 16:57
New changeset 2ea8099523581cf2ecc060831a53debb57ff98ee by Serhiy Storchaka (Stefan Behnel) in branch 'master':
bpo-9883: Update list of unimplemented interfaces in minidom. (GH-12677)
https://github.com/python/cpython/commit/2ea8099523581cf2ecc060831a53debb57ff98ee
msg339588 - (view) Author: miss-islington (miss-islington) Date: 2019-04-08 02:56
New changeset a9a065addd175ed37a959118c90377ba60f90036 by Miss Islington (bot) in branch '3.7':
bpo-9883: Update list of unimplemented interfaces in minidom. (GH-12677)
https://github.com/python/cpython/commit/a9a065addd175ed37a959118c90377ba60f90036
msg343994 - (view) Author: Cheryl Sabella (cheryl.sabella) * (Python committer) Date: 2019-05-30 19:23
I've closed PR1745 as it appeared to be abandoned.
History
Date User Action Args
2022-04-11 14:57:06adminsetgithub: 54092
2019-05-30 19:23:03cheryl.sabellasetnosy: + cheryl.sabella
messages: + msg343994
2019-04-08 02:56:03miss-islingtonsetnosy: + miss-islington
messages: + msg339588
2019-04-07 05:15:06miss-islingtonsetpull_requests: + pull_request12638
2019-04-06 16:58:25miss-islingtonsetpull_requests: + pull_request12634
2019-04-06 16:57:46serhiy.storchakasetmessages: + msg339539
2019-04-03 17:47:25scodersetmessages: + msg339405
2019-04-03 17:47:12scodersetkeywords: + patch
stage: patch review
pull_requests: + pull_request12604
2019-04-03 11:39:28James Socolsetnosy: - jamessocol
2019-04-03 05:35:40xtreaksetnosy: + scoder, serhiy.storchaka
2019-04-03 04:29:52fdrakesetmessages: + msg339377
versions: + Python 3.8, - Python 3.5
2017-05-23 04:06:20fdrakesetnosy: + fdrake
messages: + msg294218
2017-05-23 00:30:04arp11setpull_requests: + pull_request1834
2017-05-23 00:16:34BreamoreBoysetnosy: - BreamoreBoy
2017-05-22 20:41:12arp11setpull_requests: + pull_request1814
2014-10-02 22:27:04BreamoreBoysetversions: + Python 3.5, - Python 2.6
nosy: + BreamoreBoy

messages: + msg228270

type: behavior -> enhancement
2013-05-23 17:02:00jamessocolsetnosy: + jamessocol
2010-09-17 03:30:39Aubrey.Barnardcreate