Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I am still quite certain that there is a bug in Chrome's <code>XMLSerializer</code>, most likely introduced while addressing the <a href="https://stackoverflow.com/questions/8979267/xmlserializer-strips-xlink-from-xlinkhtml-svg-image-tag">SVG handling of XLink attributes that Barbarrosa pointed to</a>. But given the lack of response to the <a href="http://code.google.com/p/chromium/issues/detail?id=155135" rel="nofollow noreferrer">bug report</a> I made for it, we've had to move forward and work around the problem. </p> <p>We work around the problem by calling this function on the <code>documentElement</code>:</p> <pre><code>function EnsureXLinkNamespaceOnElement(element) { if (element.nodeType == 1) { var usesXLinkNamespaceUri = false; var hasXLinkNamespacePrefixDefined = false; for (var i = 0; i &lt; element.attributes.length; i++) { var attribute = element.attributes[i]; if (attribute.specified) { if (attribute.name.indexOf("xmlns:xlink") == 0) { hasXLinkNamespacePrefixDefined = true; } else if (attribute.namespaceURI == "http://www.w3.org/1999/xlink") { usesXLinkNamespaceUri = true; } } } if (usesXLinkNamespaceUri &amp;&amp; !hasXLinkNamespacePrefixDefined) { element.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink'); } for (i = 0; i &lt; element.childNodes.length; i++) { EnsureXLinkNamespaceOnElement(element.childNodes[i]); } } } </code></pre> <p>The function simply ensures that the <code>xmlns:xlink</code> attribute is declared on any element that has attributed in the XLink namespace. Since the function traverses the tree and thus can be quite time-consuming, I only invoke it for Chrome versions 22 and higher.</p> <p>Note that in most cases you could also get away with simply adding the <code>xmlns:xlink</code> namespace on the document element, since it will be inherited from there. But in our case there was some other code that strips the document element using a regular expression, so we decided to play it safe and simply add the attribute everywhere it may be needed.</p> <h1>Update (20130324):</h1> <p>The <a href="https://code.google.com/p/chromium/issues/detail?id=155135" rel="nofollow noreferrer">bug</a> was fixed and verified in Chrome Canary 26. I have been able to verify it myself on version <code>25.0.1364.172 m</code> too.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload