相关疑难解决方法(0)

xmlserializer从xlink:html svg图像标记中剥离xlink

我正在创建一个javascript界面​​,以便将xlinked图像动态添加到教室地图中.

 //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");
Run Code Online (Sandbox Code Playgroud)

图像附加并在屏幕上显示如下标签:

<image x="0" y="0" height="80" width="40" xlink:href="roomlayouts/items/cactus.svg"></image>
Run Code Online (Sandbox Code Playgroud)

但是一旦我通过xmlserializer传递它以便我可以保存文件,它会从前面剥离xlink标记:

var svgDoc = document.getElementById('SVGMap');
var serializer = new XMLSerializer();
var xmlString = serializer.serializeToString(svgDoc.firstChild);
Run Code Online (Sandbox Code Playgroud)

创建:

<image x="0" y="0" width="40" height="80" href="roomlayouts/items/cactus.svg"></image>
Run Code Online (Sandbox Code Playgroud)

这意味着svg失去了cactii.有什么想法我怎么能让xmlserializer保持xlink前缀?

==============================注意:这是webkit中的一个错误,现在已经解决了.请参阅以下讨论以获取错误报告的链接

javascript html5 svg xmlserializer

5
推荐指数
1
解决办法
2971
查看次数

标签 统计

html5 ×1

javascript ×1

svg ×1

xmlserializer ×1