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
I think this is probably *not* desirable in this form. As a side effect of writexml(), this fixes up tagNames and attributes of elements in the document. DOM Level 3 Load and Save made the opposite decision: "The XML data is written to a string or an output stream. Any changes or fixups made during the serialization affect only the serialized data. The Document object and its children are never altered by the serialization operation." -- http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/load-save.html#LS-LSSerializer (first paragraph) I think that is the right approach.
The new method Element.normalizeNamespace() isn't really a DOM method, though the appendix sort of makes it look that way.
Incomplete - no doc patch. (I think there's also a bug in the line added to Document.writexml()-- can't Documents have children that aren't Elements?)
msg51609 doesn't seem too enthusiastic about the patch. msg84599 states unit tests are provided and bpo-1371937 is fixed. Can we have a definitive statement as to whether the patch is acceptable or not.
The tests don't run correctly, so they cannot be uses as-is to assess the fix. Given the 15 years without an update on this issue, I'm setting it to pending. If someone wants to update the tests and patch, we can keep it open until it's fixed.
#156674 fixes this in the way @jorend asked for in 2007: Element.writexml() writes the namespace declarations which are missing for the element and its attributes, without changing the document, as DOM Level 3 LS requires. It covers the cases of @paulpach's patch and test (an element and an attribute created with createElementNS()/setAttributeNS(), a prefix declared for an ancestor, the default namespace, an attribute in a namespace without a prefix), plus xmlns="" for an element in no namespace under a default namespace, and it reuses a prefix which is already bound to the namespace instead of inventing one.
The normalizeNamespaces() algorithm of DOM Level 3 Core is not implemented, that is a separate feature.
Activity
paulpach commentedon Dec 23, 2006
This is a patch that fixes bug 1371937, along with a test case that reproduces the original problem.
The patch is a port of the algorithm described here pretty much verbatim:
http://www.w3.org/TR/DOM-Level-3-Core/namespaces-algorithms.html#normalizeDocumentAlgo
to resolve namespace declarations. The patch also calls the normalizeNamespace method before calling writexml
Note the patch is against minidom that comes with python 2.5, NOT WITH PYXML. I need this for an embedded project where pyxml is too big.
paulpach commentedon Dec 23, 2006
File Added: normalizeNamespace.diff
paulpach commentedon Dec 24, 2006
File Added: normalizeNamespace.diff
paulpach commentedon Dec 24, 2006
File Added: test_toxml.py
jorend commentedon Mar 15, 2007
Thanks for the patch.
I think this is probably *not* desirable in this form. As a side effect of writexml(), this fixes up tagNames and attributes of elements in the document. DOM Level 3 Load and Save made the opposite decision: "The XML data is written to a string or an output stream. Any changes or fixups made during the serialization affect only the serialized data. The Document object and its children are never altered by the serialization operation." -- http://www.w3.org/TR/2004/REC-DOM-Level-3-LS-20040407/load-save.html#LS-LSSerializer (first paragraph) I think that is the right approach.
The new method Element.normalizeNamespace() isn't really a DOM method, though the appendix sort of makes it look that way.
Incomplete - no doc patch. (I think there's also a bug in the line added to Document.writexml()-- can't Documents have children that aren't Elements?)
devdanzin commentedon Mar 30, 2009
Patch has tests, fixes bpo-1371937.
BreamoreBoy commentedon Jul 16, 2010
msg51609 doesn't seem too enthusiastic about the patch. msg84599 states unit tests are provided and bpo-1371937 is fixed. Can we have a definitive statement as to whether the patch is acceptable or not.
devdanzin commentedon Sep 20, 2025
The tests don't run correctly, so they cannot be uses as-is to assess the fix. Given the 15 years without an update on this issue, I'm setting it to pending. If someone wants to update the tests and patch, we can keep it open until it's fixed.
serhiy-storchaka commentedon Sep 13, 2026
#156674 fixes this in the way @jorend asked for in 2007:
Element.writexml()writes the namespace declarations which are missing for the element and its attributes, without changing the document, as DOM Level 3 LS requires. It covers the cases of @paulpach's patch and test (an element and an attribute created withcreateElementNS()/setAttributeNS(), a prefix declared for an ancestor, the default namespace, an attribute in a namespace without a prefix), plusxmlns=""for an element in no namespace under a default namespace, and it reuses a prefix which is already bound to the namespace instead of inventing one.The
normalizeNamespaces()algorithm of DOM Level 3 Core is not implemented, that is a separate feature.Merge remote-tracking branch 'upstream/main' into pythongh-44376-ns-f…
gh-44376: Write missing namespace declarations in xml.dom.minidom (GH…
pythongh-44376: Write missing namespace declarations in xml.dom.minid…