我在HTML文档中有一个SVG元素,我想将其导出为文本。
我知道HTML没有命名空间因此它不尊重它,这可能是我失去SVG元素上的命名空间前缀的原因。
除了编写自己的序列化程序之外,还有其他方法可以保留它吗?
示例代码:
var s = new XMLSerializer(); var svg = document.getElementById('mySvg'); console.log(s.serializeToString(svg)); //All namespace prefixes are gone!编辑:显然这是Chrome(在v17上测试)的错误。
I have an SVG element inside HTML document that I'd like to export as text.
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?
Example code:
var s = new XMLSerializer(); var svg = document.getElementById('mySvg'); console.log(s.serializeToString(svg)); //All namespace prefixes are gone!Edit: apparently this is Chrome's (tested on v17) bug.
最满意答案
这是chrome的错误: http : //code.google.com/p/chromium/issues/detail? id = 88295
现在,我必须在调用serializeToString后手动执行搜索/替换命名空间。
This is chrome's bug: http://code.google.com/p/chromium/issues/detail?id=88295
For now I have to manually do a search/replace namespaces after calls to serializeToString.
更多推荐
发布评论