Bug 117394 - DOMSerializer creates invalid XML when setAttributeNS() has been used
Summary: DOMSerializer creates invalid XML when setAttributeNS() has been used
Status: RESOLVED CONFIGURATION CHANGED
Alias: None
Product: WebKit
Classification: Unclassified
Component: DOM (show other bugs)
Version: 528+ (Nightly build)
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Nobody
URL: http://jsfiddle.net/c4jBw/
Keywords:
Depends on:
Blocks:
 
Reported: 2013-06-10 00:55 PDT by Thomas W.
Modified: 2022-08-13 22:28 PDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas W. 2013-06-10 00:55:24 PDT
== Overview ==

When serializing a document where attributes have been added using .setAttributeNs(), the serialization is invalid XML.


== Steps to Reproduce ==

Execute the following code:

  var doc = (new DOMParser()).parseFromString("<test xmlns='http://www.example.com'/>","text/xml");
  doc.documentElement.setAttributeNS("http://www.w3.org/XML/1998/namespace","id","abc");
  doc.documentElement.setAttributeNS("http://www.example.com/dummy/namespace","foo","bar");
  console.log((new XMLSerializer()).serializeToString(doc));

(can be found at http://jsfiddle.net/c4jBw/)


== Actual Results ==

  <test xmlns="http://www.example.com" id="abc" xmlns="http://www.w3.org/XML/1998/namespace" foo="bar" xmlns="http://www.example.com/dummy/namespace"/> 


== Expected Results ==

  <test xmlns="http://www.example.com" xml:id="abc" a0:foo="bar" xmlns:a0="http://www.example.com/dummy/namespace"/>


== Software Version ==

First encountered with Safari 5.1.7 (7534.57.2) on Windows 7


== Additional Comments ==

The main problem are three xmlns attributes.  The second problem is that the added attributes are in the null namespace.

The correct example output is taken from Firefox 21.
Comment 1 Rob Buis 2013-07-16 13:17:12 PDT
This seems rather like other serializing bugs, like bug 19121? I am quite sure that fixing that one fixes this one too.
Comment 2 Lucas Forschler 2019-02-06 09:02:31 PST
Mass moving XML DOM bugs to the "DOM" Component.
Comment 3 Ahmad Saleem 2022-08-12 11:41:34 PDT
*** Safari Technical Preview 151 ****

> In JSFiddle:

"&lt;test xmlns=\&quot;http://www.example.com\&quot; xml:id=\&quot;abc\&quot; NS1:foo=\&quot;bar\&quot; xmlns:NS1=\&quot;http://www.example.com/dummy/namespace\&quot;/&gt;"

> In Browser Console:

<test xmlns="http://www.example.com" xml:id="abc" NS1:foo="bar" xmlns:NS1="http://www.example.com/dummy/namespace"/>


** Chrome Canary 106 ***

> In JSFiddle:

"&lt;test xmlns=\&quot;http://www.example.com\&quot; xml:id=\&quot;abc\&quot; xmlns:ns1=\&quot;http://www.example.com/dummy/namespace\&quot; ns1:foo=\&quot;bar\&quot;/&gt;"

> In Browser Console:

<test xmlns="http://www.example.com" xml:id="abc" xmlns:ns1="http://www.example.com/dummy/namespace" ns1:foo="bar"/>


*** Firefox Nightly 105 ***

> In JSFiddle:

"&lt;test xmlns=\&quot;http://www.example.com\&quot; xml:id=\&quot;abc\&quot; a0:foo=\&quot;bar\&quot; xmlns:a0=\&quot;http://www.example.com/dummy/namespace\&quot;/&gt;"

> In Browser Console:

<test xmlns="http://www.example.com" xml:id="abc" NS1:foo="bar" xmlns:NS1="http://www.example.com/dummy/namespace"/>

___________

I am not sure now web-spec so I am going to just post updated results. Thanks!
Comment 4 Ryosuke Niwa 2022-08-13 22:28:55 PDT
This appears to be working now.