Closed Bug 251573 Opened 21 years ago Closed 20 years ago

Missing namespace declarations when adding NS'ed elements/attributes to a document programmatically

Categories

(Core :: DOM: Serializers, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: zigsterz, Assigned: peterv)

References

()

Details

(Keywords: fixed-aviary1.0, fixed1.7.5)

Attachments

(1 file)

User-Agent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.1.4322; .NET CLR 1.0.3705) Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.7.1) Gecko/20040707 The problem manifested itself in two forms: (a) Doing a attr=createAttributeNS, then element.setAttributeNode(attr) should trigger the creation of a namespace declaration for attr.namespaceURI on element. It doesn't. (b) When doing appendChild(elem) where elem=createElementNS(...), a namespace declaration isn't emitted if a previous element with the same namespace prefix/URI was appended to the same parent without children. Demonstration code snippet: var doc = document.implementation.createDocument("", "", null); doc.appendChild(doc.createElement("R")); lE1 = doc.createElementNS("http://one.org/", "a:one"); doc.documentElement.appendChild(lE1); lE1.appendChild(doc.createTextNode("")); // <------ *** lE2 = doc.createElementNS("http://one.org/", "a:two"); doc.documentElement.appendChild(lE2); alert("DOC: " + ( new XMLSerializer ).serializeToString( doc )); When removing the line marked with asterisks, lE2 won't include a namespace declaration -- only lE1. Probably in the absence of a closing tag someone forgets to change the namespace resolution context. Reproducible: Always Steps to Reproduce: See details. Actual Results: See details.
Please attach a testcase showing the problem (and if there are two distinct problems, please file two separate bugs on them).
Assignee: general → dom-to-text
Component: DOM → DOM to Text Conversion
QA Contact: ian
And please point out what part of the spec we're not following.
Problem a isn't a bug: you need to use setAttributeNodeNS. To fix problem b we probably need to add a call to PopNameSpaceDeclsFor at the end of nsXMLContentSerializer::AppendElementStart for the case of an element without children (http://lxr.mozilla.org/seamonkey/source/content/base/src/nsXMLContentSerializer.cpp#592).
Status: UNCONFIRMED → NEW
Ever confirmed: true
Actually, it probably should be in nsXMLContentSerializer::AppendElementEnd (http://lxr.mozilla.org/seamonkey/source/content/base/src/nsXMLContentSerializer.cpp#611).
Attached patch v1Splinter Review
Assignee: dom-to-text → peterv
Status: NEW → ASSIGNED
Attachment #153872 - Flags: superreview?(bzbarsky)
Attachment #153872 - Flags: review?(bzbarsky)
Comment on attachment 153872 [details] [diff] [review] v1 r+sr=bzbarsky
Attachment #153872 - Flags: superreview?(bzbarsky)
Attachment #153872 - Flags: superreview+
Attachment #153872 - Flags: review?(bzbarsky)
Attachment #153872 - Flags: review+
Comment on attachment 153872 [details] [diff] [review] v1 Trivial fix so that the XML serializer doesn't create invalid XML documents. Low risk.
Attachment #153872 - Flags: approval1.7.2?
Attachment #153872 - Flags: approval1.7.2? → approval1.7.2+
Checked in to the (closed) 1.7 branch. Didn't notice it was closed, so feel free to bug me it it needs to be backed out.
Status: ASSIGNED → RESOLVED
Closed: 20 years ago
Keywords: fixed1.7
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: