Closed Bug 326994 Opened 19 years ago Closed 19 years ago

XMLSerializer adds namespace declaration for non-empty prefix with empty namespace name

Categories

(Core :: XML, defect)

defect
Not set
normal

Tracking

()

RESOLVED FIXED

People

(Reporter: surkov, Assigned: peterv)

References

Details

Attachments

(2 files, 3 obsolete files)

User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9a1) Gecko/20051212 Firefox/1.6a1 Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.9a1) Gecko/20051212 Firefox/1.6a1 When instance is created dynamically then instance document submitted with namespace prefix "a0". Something like that: <a0:root xmlns:a0="" xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"/> The problem is DOMParser fails when it parse such document. Probably it is isn't xforms problem and I just want to understand what's happen. Reproducible: Always
Attached file testcase (obsolete) (deleted) —
Attached file testcase (obsolete) (deleted) —
Attachment #211719 - Attachment is obsolete: true
Attached file xml parse feature (obsolete) (deleted) —
The first issue isn't related with XForms. I'm not sure whether the issue is bug or not but the strange behaviour surely. If element has attribute xmlns="uri1" and I set attribute xmlns="uri2" on it then element has two attributes xmlns="uri2" and xmlns:a0="uri1". When I serialize the element and then I parse it then I get exception.
The second issue is related with xforms, and it probably isn't a bug too. But I guess it is needed in some discussion. The question is following. If instance document root contains default empty namespace (xmlns="") then why we should change default namespace on it from owner document? In instance: <html xmlns="xhtml namespace uri" xmlns:xforms="xforms namespace uri"> <xforms:model> <xforms:instance> <instanceRoot xmlns=""/> </xforms:instance> </xforms:model> </html> Result: <a0:instanceRoot xmlns:a0="" xmlns="html namespace uri"/> I can't see the utility of it. Any reason?
Attachment #211720 - Attachment mime type: text/plain → application/xhtml+xml
Hmm, there seems to be something weird happening. At least you should be able to serialize some XML, and then parse it afterwards. Peter, can you educate us here? :)
About what?
(In reply to comment #6) > About what? About why we get a parseerror in attachment 211807 [details] This happens on trunk, but on on 1.8.0.
You need to use setAttributeNS to set xmlns attributes. You're adding a xmlns attribute with no namespace, there's no good way to serialize that. Also see http://lxr.mozilla.org/seamonkey/source/content/base/src/nsXMLContentSerializer.cpp#600
IMHO we should throw on the setAttribute call.
(In reply to comment #8) > You need to use setAttributeNS to set xmlns attributes. You're adding a xmlns > attribute with no namespace, there's no good way to serialize that. Also see > http://lxr.mozilla.org/seamonkey/source/content/base/src/nsXMLContentSerializer.cpp#600 Ah. (In reply to comment #9) > IMHO we should throw on the setAttribute call. That would be nice. I would have caught the error earlier at least.
(In reply to comment #8) > You need to use setAttributeNS to set xmlns attributes. You're adding a xmlns > attribute with no namespace, there's no good way to serialize that. Also see > http://lxr.mozilla.org/seamonkey/source/content/base/src/nsXMLContentSerializer.cpp#600 > Do you mean I should write the something like that? root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://www.w3.org/1999/xhtml"); The behaviour remains the same.
(In reply to comment #4) > The second issue is related with xforms, and it probably isn't a bug too. But I > guess it is needed in some discussion. The question is following. If instance > document root contains default empty namespace (xmlns="") then why we should > change default namespace on it from owner document? > > I can't see the utility of it. Any reason? > I can't find anything in the specs about inheritance default namespace. Note, if I understand right, model owner document, model element, instance element and instance document can have different default namespaces. There is not a way to control default naemspaces. Imo the default namespaces should not be inherited. Am I wrong? Btw #default value in @includenamespaceprefixes isn't supported.
Morphing this bug, please file the XForms issue as a separate bug if it is one. We should not add a namespace declaration for a non-empty prefix with an empty namespace name, see http://www.w3.org/TR/REC-xml-names/#dt-prefix
Assignee: aaronr → xml
Status: UNCONFIRMED → NEW
Component: XForms → XML
Ever confirmed: true
QA Contact: spride → ashshbhatt
Summary: dynamic instance submission issue → XMLSerializer adds namespace declaration for non-empty prefix with empty namespace name
Attached patch v1 (deleted) — Splinter Review
Boris, what do you think? This patch makes us drop an attribute in the case of: var doc = ParseXML('<root xmlns=""/>') var root = doc.documentElement; root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", "http://www.w3.org/1999/xhtml"); so when serializing root we end up with: <root/> The alternative is to output: <root xmlns:a0="http://www.w3.org/1999/xhtml"/> Note that in the case of var doc = ParseXML('<root xmlns="http://www.w3.org/1999/xhtml"/>') var root = doc.documentElement; root.setAttributeNS("http://www.w3.org/2000/xmlns/", "xmlns", ""); we output: <a0:root xmlns:a0="http://www.w3.org/1999/xhtml" xmlns=""/>
Assignee: xml → peterv
Status: NEW → ASSIGNED
Attachment #212110 - Flags: superreview?(bzbarsky)
Attachment #212110 - Flags: review?(bzbarsky)
Attached file Testcase (deleted) —
Attachment #211720 - Attachment is obsolete: true
Attachment #211807 - Attachment is obsolete: true
Comment on attachment 212110 [details] [diff] [review] v1 >Index: content/base/src/nsXMLContentSerializer.cpp >+ skipAttr = index; Right before that, assert that skipAttr == count? Or can we not do that? That is, can we have two separate prefix-less "xmlns" attrs? If we can, it seems like this fix won't work... Or is the plan to do this and then throw on prefix-less xmlns attrs not in the xmlns namespace? r+sr=bzbasky with that sorted out.
Attachment #212110 - Flags: superreview?(bzbarsky)
Attachment #212110 - Flags: superreview+
Attachment #212110 - Flags: review?(bzbarsky)
Attachment #212110 - Flags: review+
(In reply to comment #16) > Or is the plan to do this and then throw on prefix-less xmlns attrs not in the > xmlns namespace? Yes, and it's bug 315805.
Status: ASSIGNED → RESOLVED
Closed: 19 years ago
Resolution: --- → FIXED
Blocks: 301260
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: