Javascript:使用XMLSerialier.serializeToString()时如何保留名称空间? [英] Javascript: How to preserve namespace when using XMLSerialier.serializeToString()?
问题描述
我在HTML文档中有一个SVG元素,我想将其导出为文本.
I have an SVG element inside HTML document that I'd like to export as text.
我知道HTML没有命名空间,因此它不兑现命名空间,这可能就是为什么我在SVG元素上丢失命名空间前缀的原因.
I know HTML doesn't have namespace hence it doesn't honor one, that is probably why I lose namespace prefixes on my SVG element.
除了编写自己的序列化程序外,还有其他方法可以保留它吗?
Are there ways to preserve it other than writing my own serializer?
示例代码:
var s = new XMLSerializer();
var svg = document.getElementById('mySvg');
console.log(s.serializeToString(svg)); //All namespace prefixes are gone!
显然,这是Chrome(已在v17上测试)的错误.
apparently this is Chrome's (tested on v17) bug.
推荐答案
这是Chrome的错误: http://code.google.com/p/chromium/issues/detail?id=88295
This is chrome's bug: http://code.google.com/p/chromium/issues/detail?id=88295
现在,我必须在调用serializeToString
之后手动进行搜索/替换名称空间.
For now I have to manually do a search/replace namespaces after calls to serializeToString
.
这篇关于Javascript:使用XMLSerialier.serializeToString()时如何保留名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!