Javascript:如何在使用XMLSerialier.serializeToString()时保留命名空间?(Javascript: How to preserve namespace when

编程入门 行业动态 更新时间:2024-10-27 18:22:58
Javascript:如何在使用XMLSerialier.serializeToString()时保留命名空间?(Javascript: How to preserve namespace when using XMLSerialier.serializeToString()?)

我在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.

更多推荐

本文发布于:2023-08-02 18:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1379423.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:如何在   空间   XMLSerialier   Javascript   namespace

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!