You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ElementTree.tostring(..., default_namespace=...) incorrectly strips namespace from attributes #113581
In the expected output the namespace name of the attribute is http://example.com, but in the actual output the namespace name of the attribute has no value.
Note that our parser does correctly implement this part of the "Namespaces in XML" specification
# Prints {'{http://example.com}baz': '1234'}print(ET.XML('''<foo xmlns="http://example.com" xmlns:ns0="http://example.com" ns0:baz="1234" />''').attrib)
# Prints {'baz': '1234'}print(ET.XML('''<foo xmlns="http://example.com" baz="1234" />''').attrib)
changed the title [-]ElementTree: default_namespace incorrectly strips napespace from attributes[/-][+]ElementTree.tostring(..., default_namespace=...) incorrectly strips napespace from attributes[/+]on Dec 30, 2023
changed the title [-]ElementTree.tostring(..., default_namespace=...) incorrectly strips napespace from attributes[/-][+]ElementTree.tostring(..., default_namespace=...) incorrectly strips namespace from attributes[/+]on Dec 30, 2023
A default namespace declaration does not apply to attribute names, so a qualified attribute name always needs a prefix, and its namespace ends up declared twice:
Activity
[-]ElementTree: default_namespace incorrectly strips napespace from attributes[/-][+]ElementTree.tostring(..., default_namespace=...) incorrectly strips napespace from attributes[/+][-]ElementTree.tostring(..., default_namespace=...) incorrectly strips napespace from attributes[/-][+]ElementTree.tostring(..., default_namespace=...) incorrectly strips namespace from attributes[/+]serhiy-storchaka commentedon Aug 31, 2026
PR #156747 fixes this, together with gh-61290.
A default namespace declaration does not apply to attribute names, so a qualified attribute name always needs a prefix, and its namespace ends up declared twice:
This is the output you expected, except for the generated prefix. lxml serializes it the same way.
gh-61290: Fix serializing attributes with the default_namespace option (
pythongh-61290: Fix serializing attributes with the default_namespace…