title: Subtle difference in XMLSerializer in Firefox vs Chrome?
body: <p>The following snippet of code converts a Javascript object into an XML string using the createDocument and XMLSerializer APIs. The problem is that it generates different outputs on Chrome (23.0.1271.101) and Firefox (14.0.1) browsers. </p>
  
  <pre><code>var item = { _dto: {...} }; // the 'model' object
  var xmlDto = $('&lt;Column /&gt;'); // this is eventually serialized and sent to the server
  var optionalTags = ['Abstract', 'Note', 'Size', 'Digits', 'Nullable', 'AutoUpdate', 'DataType'];
  
  // convert badgerfish JSON back to XML.
  // use XML because it is not possible serialize JSON and preserve key order.
  var xmlDoc = document.implementation.createDocument("http://example.org/v1", "Column", null);
  var root = xmlDoc.childNodes[0];
  var nameTag = xmlDoc.createElement("Name");
  nameTag.setAttribute('uuid', item._dto['Name']['@uuid']);
  nameTag.textContent=item._dto['Name']['$'];
  root.appendChild(nameTag);
  optionalTags.map(function (tagName) {
      var tag = xmlDoc.createElement(tagName);
      tag.textContent=item._dto[tagName];
      if (item._dto.hasOwnProperty(tagName)) {
          tag.textContent=item._dto[tagName];
          root.appendChild(tag);
      }
  });
  
  var xmlStr = new XMLSerializer().serializeToString(xmlDoc);
  xmlStr = '&lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;'+xmlStr;
  </code></pre>
  
  <p>On Chrome, the following desired/expected output is generated:</p>
  
  <pre><code>    &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
      &lt;Column xmlns="http://example.org/v1"&gt;
            &lt;Name uuid="001b5cbe-bab7-4880-90b6-9e8f47f6e4af"&gt;FAILED_ID&lt;/Name&gt;
            &lt;Size&gt;38&lt;/Size&gt;
            &lt;Digits&gt;0&lt;/Digits&gt;
            &lt;Nullable&gt;true&lt;/Nullable&gt;
            &lt;AutoUpdate&gt;false&lt;/AutoUpdate&gt;
            &lt;DataType&gt;NUMERIC&lt;/DataType&gt;
      &lt;/Column&gt;
  </code></pre>
  
  <p>But in Firefox, the generated output has the <code>xmlns</code> attribute inserted in every tag with an empty value:</p>
  
  <pre><code>     &lt;?xml version="1.0" encoding="UTF-8" standalone="yes"?&gt;
       &lt;Column xmlns="http://example.org/v1"&gt;
            &lt;Name xmlns="" uuid="001b5cbe-bab7-4880-90b6-9e8f47f6e4af"&gt;FAILED_ID&lt;/Name&gt;
            &lt;Size xmlns=""&gt;38&lt;/Size&gt;
            &lt;Digits xmlns=""&gt;0&lt;/Digits&gt;
            &lt;Nullable xmlns=""&gt;true&lt;/Nullable&gt;
            &lt;AutoUpdate xmlns=""&gt;false&lt;/AutoUpdate&gt;
            &lt;DataType xmlns=""&gt;NUMERIC&lt;/DataType&gt;
       &lt;/Column&gt;
  </code></pre>
  
  <p>It looks like the XMLSerializer in Firefox and Chrome have subtle differences but I need to verify this. In any case, the Firefox output is invalid XML. Can somebody shed some light on this?</p>
  
  <p>Is there a better way to generate an XML document in the browser?</p>
  
  <p>I wouldn't be doing this if in the first place I had a way to serialize to JSON with the ability to preserve key order.</p>