Skip to content

minidom: AttributeError: DocumentFragment instance has no attribute 'writexml' #54092

Closed

Description

@AubreyBarnard
BPO 9883
Nosy @freddrake, @scoder, @serhiy-storchaka, @csabella, @miss-islington
PRs
  • bpo-9883: writexml on a DocumentFragment acts on children #1726
  • bpo-9883: writexml on a DocumentFragment acts on children #1745
  • bpo-9883: Remove names from the "unimplemented interfaces" list in the minidom docs that are actually implemented. #12677
  • [3.7] bpo-9883: Update list of unimplemented interfaces in minidom. (GH-12677) #12709
  • [3.7] bpo-9883: Update list of unimplemented interfaces in minidom. (GH-12677) #12712
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = None
    created_at = <Date 2010-09-17.03:30:39.180>
    labels = ['expert-XML', 'type-feature', '3.8']
    title = "minidom: AttributeError: DocumentFragment instance has no attribute 'writexml'"
    updated_at = <Date 2019-05-30.19:23:03.512>
    user = 'https://bugs.python.org/AubreyBarnard'

    bugs.python.org fields:

    activity = <Date 2019-05-30.19:23:03.512>
    actor = 'cheryl.sabella'
    assignee = 'none'
    closed = False
    closed_date = None
    closer = None
    components = ['XML']
    creation = <Date 2010-09-17.03:30:39.180>
    creator = 'Aubrey.Barnard'
    dependencies = []
    files = []
    hgrepos = []
    issue_num = 9883
    keywords = ['patch']
    message_count = 8.0
    messages = ['116644', '228270', '294218', '339377', '339405', '339539', '339588', '343994']
    nosy_count = 6.0
    nosy_names = ['fdrake', 'scoder', 'Aubrey.Barnard', 'serhiy.storchaka', 'cheryl.sabella', 'miss-islington']
    pr_nums = ['1726', '1745', '12677', '12709', '12712']
    priority = 'normal'
    resolution = None
    stage = 'patch review'
    status = 'open'
    superseder = None
    type = 'enhancement'
    url = 'https://bugs.python.org/issue9883'
    versions = ['Python 3.8']

    Linked PRs

    Activity

    1. AubreyBarnard commented on Sep 17, 2010

      AubreyBarnardmannequin
      MannequinAuthor

      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.

    2. BreamoreBoy commented on Oct 2, 2014

      BreamoreBoymannequin
      Mannequin

      Can someone please confirm that my assessment of this as an enhancement is correct, thanks.

    3. added
      type-featureA feature request or enhancement
      and removed
      type-bugAn unexpected behavior, bug, or error
      on Oct 2, 2014
    4. freddrake commented on May 23, 2017

      @freddrake
      Member

      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.

    5. freddrake commented on Apr 3, 2019

      @freddrake
      Member

      Updated target to Python 3.8, since this has aged a bit.

    6. scoder commented on Apr 3, 2019

      @scoder
      Contributor

      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

    7. serhiy-storchaka commented on Apr 6, 2019

      @serhiy-storchaka
      Member

      New changeset 2ea8099 by Serhiy Storchaka (Stefan Behnel) in branch 'master':
      bpo-9883: Update list of unimplemented interfaces in minidom. (GH-12677)
      2ea8099

    8. miss-islington commented on Apr 8, 2019

      @miss-islington
      Contributor

      New changeset a9a065a by Miss Islington (bot) in branch '3.7':
      bpo-9883: Update list of unimplemented interfaces in minidom. (GH-12677)
      a9a065a

    9. csabella commented on May 30, 2019

      @csabella
      Contributor

      I've closed PR1745 as it appeared to be abandoned.

    10. transferred this issue fromon Apr 10, 2022
    11. added a commit that references this issue on Sep 13, 2026
    12. serhiy-storchaka commented on Sep 13, 2026

      @serhiy-storchaka
      Member

      Fixed in 3.16 by #156646: DocumentFragment.writexml() is implemented, and toxml()/toprettyxml() work on document fragments.

    13. added 3 commits that reference this issue on Sep 13, 2026
    14. added a commit that references this issue on Sep 14, 2026
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

    Metadata

    Metadata

    Assignees

    No one assigned

      Labels

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions