<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <script type="text/javascript">
    function runTest()
    {
        if (window.testRunner)
            testRunner.dumpAsText();

        var target = document.getElementById("target");

        var svgns = "http://www.w3.org/2000/svg";
        var xmlnsns = "http://www.w3.org/2000/xmlns/";
        var xlinkns = "http://www.w3.org/1999/xlink";

        // SVG with correct xmlns prefix on xlink
        var svg = document.createElementNS(svgns, "svg");
        svg.setAttributeNS(xmlnsns, 'xmlns', svgns);
        svg.setAttributeNS(null, "svg", svgns);
        svg.setAttributeNS(xmlnsns, "xmlns:xlink", xlinkns);
        svg.setAttributeNS(null, "width", "200");
        svg.setAttributeNS(null, "height", "200");

        // Already correct xlink:href
        var image = document.createElementNS(svgns, "image");
        image.setAttributeNS(null, "width", "20");
        image.setAttributeNS(null, "height", "20");
        image.setAttributeNS(xlinkns, "xlink:href", "resources/green-checker.png");
        svg.appendChild(image);

        // Missing prefix from href. Must be added when serialized.
        var image = document.createElementNS(svgns, "image");
        image.setAttributeNS(null, "x", "0");
        image.setAttributeNS(null, "y", "30");
        image.setAttributeNS(null, "width", "20");
        image.setAttributeNS(null, "height", "20");
        image.setAttributeNS(xlinkns, "href", "resources/green-checker.png");
        svg.appendChild(image);

        target.appendChild(svg);

        var serializer = new XMLSerializer();
        var xmlString = serializer.serializeToString(target);

        var xlink_str = '<El a:title="C" a:href="H" xmlns:a="http://www.w3.org/1999/xlink" />';
        var xlink_dom = new DOMParser().parseFromString(xlink_str, 'text/xml');
        var xlink_output = serializer.serializeToString(xlink_dom);

        var svgText = document.getElementById("svgoutput");
        svgText.textContent = xmlString + "\n" + xlink_output;
    }
    </script>
</head>
    <body onload="runTest()">
        <div id="target"/>
        <div id="svgoutput"/>
    </body>
</html>
