Unwanted namespaces on SVG markup when using XMLSerializer in JavaScript with IE Unwanted namespaces on SVG markup when using XMLSerializer in JavaScript with IE xml xml

Unwanted namespaces on SVG markup when using XMLSerializer in JavaScript with IE


OK, I think I've solved it. Followed the trail from this post to this WebKit bug report and this test case.

If I change the script to this, then it works:

var el = document.createElementNS('http://www.w3.org/2000/svg', 'svg');el.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns', 'http://www.w3.org/2000/svg');el.setAttributeNS('http://www.w3.org/2000/xmlns/', 'xmlns:xlink', 'http://www.w3.org/1999/xlink');var markup = (new XMLSerializer()).serializeToString(el);console.log(markup);

Ah namespaces.

But, it fails in an older version of WebKit that is still present in Safari 6.05 and PhantomJS (bug report - now fixed). Presumably the fix is incorporated into the latest Safari update (I haven't yet checked).