GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-44871: Improve DOM Level 1 conformance of xml.dom.minidom by serhiy-storchaka · Pull Request #155641 · python/cpython

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

Rework of minidom-level-1-compliance.4.patch by Jason Orendorff (2007), which no longer applies: it is Python 2 source (ur'' literals), and its XML 1.0 name tables predate XML 1.0 Fifth Edition, which adopted the XML 1.1 Name production.

  • The factory methods now raise InvalidCharacterErr if the name is not a valid XML name. The original patch added a new module for this; xml.is_valid_name() is used instead.
  • appendChild(), insertBefore() and replaceChild() now raise WrongDocumentErr if the new child was created by other document, and HierarchyRequestErr if it is the node itself or its ancestor. The latter formerly created a cycle, in which walking parentNode never terminates and serialization fails with RecursionError.
  • Attributes defaulted in the DTD are no longer omitted when parsing, and Attr.specified now reports whether the attribute was given in the start tag. It was always false before. This needs the new pyexpat method GetSpecifiedAttributeCount().
  • EntityReference nodes and Document.createEntityReference() are now implemented.

Two parts of the original patch are not included. Document.xmlVersion existed only to select between the XML 1.0 and 1.1 name grammars, which are now identical. Making writes to nodeValue a no-op where the DOM defines it as null conflicts with #155627, which deprecates writes to read-only attributes rather than ignoring them.

Rejecting invalid names and cross-document insertions breaks code which currently succeeds, so this is documented in the porting section of What's New.

  • Issue: minidom Level 1 DOM compliance #44871
  • Issue: xml.dom docs are missing important information necessary for usage #156388

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
serhiy-storchaka added 2 commits August 12, 2026 21:56
@serhiy-storchaka
pythongh-44871: Add pyexpat GetSpecifiedAttributeCount()
feabab3
It tells how many of the attributes reported to StartElementHandler were
given in the start tag rather than defaulted from the DTD.
@serhiy-storchaka
pythongh-44871: Improve DOM Level 1 conformance of xml.dom.minidom
f59bfab
* The factory methods now raise InvalidCharacterErr if the name is not a
  valid XML name.
* appendChild(), insertBefore() and replaceChild() now raise
  WrongDocumentErr if the new child was created by other document, and
  HierarchyRequestErr if it is the node itself or its ancestor.
* Attributes defaulted in the DTD are no longer omitted when parsing, and
  Attr.specified now reports whether the attribute was given in the start
  tag.
* EntityReference nodes and Document.createEntityReference() are now
  implemented.
@serhiy-storchaka
serhiy-storchaka requested a review from AA-Turner as a code owner August 12, 2026 18:58
@bedevere-app bedevere-app Bot mentioned this pull request Aug 12, 2026
minidom Level 1 DOM compliance #44871
Closed
@bedevere-app bedevere-app Bot added the awaiting core review label Aug 12, 2026
@read-the-docs-community

read-the-docs-community Bot commented Aug 12, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown

Documentation build overview

📚 cpython-previews | 🛠️ Build #34297623 | 📁 Comparing a250705 against main (3f99ebe)

  🔍 Preview build  

59 files changed · + 1 added · ± 58 modified

+ Added

  • library/time-complexity.html

± Modified

  • glossary.html
  • c-api/import.html
  • extending/extending.html
  • faq/design.html
  • faq/programming.html
  • library/annotationlib.html
  • library/asyncio-stream.html
  • library/asyncio-subprocess.html
  • library/asyncio-task.html
  • library/audit_events.html
  • and 48 more...
All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

serhiy-storchaka added 4 commits August 13, 2026 09:22
@serhiy-storchaka
pythongh-44871: Only walk ancestors when the new child has children
9de89b7
A node without children cannot be an ancestor, so testing this first
keeps appending leaf nodes linear in the depth of the tree.

Also fix references which do not resolve on main.
@serhiy-storchaka
pythongh-44871: Fix the module reference in the NEWS entry
7672639
The documented module is xml.parsers.expat, there is no target for
pyexpat.
@serhiy-storchaka
pythongh-44871: Say "created by another document" in the What's New a…
d9a6005
…nd NEWS

Suggested by dgelessus in the review of pythonGH-155632, where the same
wording was used.
@serhiy-storchaka
pythongh-44871: Enforce the DOM constraints on children of a document
0f79c94
A document can have only one element child and only one document type
child.  This was only checked in Document.appendChild(), and only for
elements, so insertBefore() and replaceChild() could add a second one.

A document fragment no longer accepts notation children, which the DOM
does not allow.
@serhiy-storchaka serhiy-storchaka mentioned this pull request Aug 28, 2026
xml.dom docs are missing important information necessary for usage #156388
Open
16 of 19 tasks
serhiy-storchaka added 8 commits August 30, 2026 11:25
@serhiy-storchaka
Merge remote-tracking branch 'upstream/main' into pythongh-44871-mini…
fea562a
…dom-level-1
@serhiy-storchaka
pythongh-44871: Attr.specified is no longer always false
2684de3
It now reports whether the attribute was given in the start tag.
@serhiy-storchaka
pythongh-44871: Raise WrongDocumentErr in Element.setAttributeNode()
bd02e13
The DOM requires it if the attribute was created by another document.
Only insertion of child nodes was checked.
@serhiy-storchaka
pythongh-44871: Check the attribute node in NamedNodeMap.setNamedItem()
ea08b8b
It is the same interface as Element.setAttributeNode(), so it now raises
WrongDocumentErr for an attribute created by another document and
InuseAttributeErr for an attribute which belongs to another element.
@serhiy-storchaka
pythongh-44871: Add versionchanged for Attr.specified
9349d7b
It is minidom specific, so document it in the minidom documentation.
@serhiy-storchaka
pythongh-44871: Document the exceptions raised by the DOM interface
c3b3b59
The DOM requires InvalidCharacterErr for an invalid XML name,
WrongDocumentErr for a node created by another document, and
HierarchyRequestErr for making a node a descendant of itself.  None of
this was documented.
@serhiy-storchaka
Merge remote-tracking branch 'upstream/main' into pythongh-44871-mini…
6b9b489
…dom-level-1
@serhiy-storchaka
pythongh-44871: Removing an absent attribute has no effect
a250705
The DOM does not allow Element.removeAttribute() and
removeAttributeNS() to raise NotFoundErr in this case, it is a deviation
of minidom, documented in pythonGH-156636.
@serhiy-storchaka
serhiy-storchaka merged commit d636e3c into python:main Aug 30, 2026
55 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-app bedevere-app Bot removed the awaiting core review label Aug 30, 2026
@serhiy-storchaka
serhiy-storchaka deleted the gh-44871-minidom-level-1 branch August 30, 2026 10:27
@serhiy-storchaka serhiy-storchaka mentioned this pull request Aug 30, 2026
xml.dom.minidom should raise exception on invalid input #56338
Closed
clin1234 pushed a commit to clin1234/cpython that referenced this pull request Sep 12, 2026
@serhiy-storchaka @jorendorff @clin1234
pythongh-44871: Improve DOM Level 1 conformance of xml.dom.minidom (p…
ccd3d5a
…ython#155641)

* The factory methods now raise InvalidCharacterErr if the name is not
  a valid XML name.
* Inserting or setting a node created by another document now raises
  WrongDocumentErr.
* Setting an attribute node which belongs to another element now raises
  InuseAttributeErr.
* Inserting a node into itself or its descendant now raises
  HierarchyRequestErr.
* A document can have only one element child and only one document type
  child, and a document fragment can no longer have notation children.
* Removing an absent attribute now has no effect instead of raising
  NotFoundErr.
* Attributes defaulted in the DTD are no longer omitted when parsing,
  and Attr.specified now reports whether the attribute was given in the
  start tag.  This needs the new pyexpat method
  GetSpecifiedAttributeCount().
* EntityReference nodes and Document.createEntityReference() are now
  implemented.
* The exceptions required by the DOM are now documented, and minidom
  specific differences are described in the minidom documentation.

Co-authored-by: Jason Orendorff <[email protected]>
@serhiy-storchaka serhiy-storchaka mentioned this pull request Sep 14, 2026
[3.14] gh-63882: Implement empty tests in test_minidom (GH-156677) #157426
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@AA-Turner AA-Turner Awaiting requested review from AA-Turner AA-Turner is a code owner

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

1 participant

@serhiy-storchaka
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.