Skip to content

GH-113425: Add example for default_namespace in ElementTree docs#147976

Open
Rohithdgrr wants to merge 1 commit intopython:mainfrom
Rohithdgrr:doc-fix-113425
Open

GH-113425: Add example for default_namespace in ElementTree docs#147976
Rohithdgrr wants to merge 1 commit intopython:mainfrom
Rohithdgrr:doc-fix-113425

Conversation

@Rohithdgrr
Copy link
Copy Markdown

@Rohithdgrr Rohithdgrr commented Apr 1, 2026

Summary

Adds an example to the ElementTree documentation showing how to use the default_namespace parameter to preserve default namespaces during XML serialization.

Problem

When serializing XML that contains a default namespace, ElementTree adds a generated ns0: prefix instead of preserving the default namespace. This behavior is documented but lacks a clear example showing the workaround.

Solution

Added a new subsection "Serializing XML with Default Namespace" in the Tutorial section with:

  • Example showing the problem (ns0 prefix appearing)
  • Example showing the solution (using default_namespace parameter)

Issue

Fixes #113425

Checklist

  • Documentation changes in Doc/library/xml.etree.elementtree.rst
  • Includes code examples with expected output
  • References the relevant parameter default_namespace added in 3.8

📚 Documentation preview 📚: https://cpython-previews--147976.org.readthedocs.build/

Serializing XML with Default Namespace
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

.. _elementtree-xpath:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep the target for the following section

.. _elementtree-xpath:
When serializing XML that contains a default namespace, ElementTree will by
default add a generated prefix (such as ``ns0``) instead of preserving the
default namespace. For example::
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don’t agree with the phrasing here! (after instead of)

@merwok
Copy link
Copy Markdown
Member

merwok commented Apr 1, 2026

Please disclose if you use chatbots to assist contribution. (I have a suspicion because of the way the PR message is structured.)

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

Labels

awaiting review docs Documentation in the Doc dir skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

Add example to ElementTree documentation for default namespace (to avoid spurious ns0: namespace prefix)

2 participants