Skip to content

gh-44871: Improve DOM Level 1 conformance of xml.dom.minidom - #155641

Open
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:gh-44871-minidom-level-1
Open

gh-44871: Improve DOM Level 1 conformance of xml.dom.minidom#155641
serhiy-storchaka wants to merge 2 commits into
python:mainfrom
serhiy-storchaka:gh-44871-minidom-level-1

Conversation

@serhiy-storchaka

@serhiy-storchaka serhiy-storchaka commented Aug 12, 2026

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.

It tells how many of the attributes reported to StartElementHandler were
given in the start tag rather than defaulted from the DTD.
* 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.
@read-the-docs-community

Copy link
Copy Markdown

Documentation build overview

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

  🔍 Preview build  

6 files changed · ± 6 modified

± Modified

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant