I'm creating a javascript interface to dynamically add xlinked images to a map of a classroom.
//declare the xlink namespace in the svg header
xmlns:xlink="http://www.w3.org/1999/xlink"
...
//the code to append the image
var temp = document.createElementNS(svgns,"image");
temp.setAttributeNS(null,"x","0");
temp.setAttributeNS(null,"y","0");
temp.setAttributeNS(null,"height","80");
temp.setAttributeNS(null,"width","40");
temp.setAttributeNS("http://www.w3.org/1999/xlink","xlink:href","roomlayouts/items/ cactus.svg");
The image appends and displays on the screen with tags like so:
<image x="0" y="0" height="80" width="40" xlink:href="roomlayouts/items/cactus.svg"></image>
But once I pass it through the xmlserializer so that I can save the file, it strips the xlink tag off the front:
var svgDoc = document.getElementById('SVGMap');
var serializer = new XMLSerializer();
var xmlString = serializer.serializeToString(svgDoc.firstChild);
creating:
<image x="0" y="0" width="40" height="80" href="roomlayouts/items/cactus.svg"></image>
This means the svg loses the cactii. Any ideas how I can get the xmlserializer to keep the xlink prefix?
============================== NOTE: this was a bug in webkit that has now been resolved. See discussion below for link to bug report