在IE9中,导入的节点似乎没有被识别为SVG元素 [英] In IE9, Imported nodes do not seem to be recognized as SVG Elements

查看:123
本文介绍了在IE9中,导入的节点似乎没有被识别为SVG元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用importNode()方法将几个元素添加到现有的SVG文档中;一切似乎都很好;可以使用getElementsByTagName > [getElementById()不是有效] ,但是问题在于导入的元素没有被识别为SVGGElement,而只是作为[object Element]提及.有想法的人吗?

I am adding couple of elements into the existing SVG document using the importNode() method; everything seems to be fine; could get the newly added elements using getElementsByTagName [getElementById() is not working] but the problem is that the imported elements are not getting recognized as SVGGElements instead they are mentioned just as [object Element]s. any idea guys?

推荐答案

xml文件中的元素需要定义它们所在的名称空间,否则它们将被解析为未知的xml元素.

The elements inside an xml file need to define what namespace they're in, otherwise they'll get parsed as unknown xml elements.

即使xml文件的根是< svg>元素,也是如此.为了确保将元素解析为正确的svg元素,您应该添加xmlns="http://www.w3.org/2000/svg"并可能添加xmlns="http://www.w3.org/1999/xlink(如果在文件中的任何位置使用xlink属性).

This is true even if the root of the xml file was an <svg> element. To make sure that the elements get parsed as proper svg elements, you should add xmlns="http://www.w3.org/2000/svg" and possibly xmlns="http://www.w3.org/1999/xlink (if you use xlink attributes anywhere in the file).

另一方面,如果您使用html5解析器来解析元素,则约束是相似的,但略有不同,因为xmlns属性无法在html中识别(仅在xhtml中).在这种情况下,您至少需要一个< svg>元素根才能将标记解析为svg,并且需要确保将标记检测为html5(避免使用任何特定于浏览器的传统后备模式).因此,如果您使用html5解析器,则不能将< g>元素作为根.

If on the other hand you parsed the elements using an html5 parser, the constraints are similar but slightly different since xmlns attributes aren't recognized in html (only in xhtml). You'd need at least an <svg> element root for the markup to get parsed as svg in such a case, and you'd need to make sure that the markup is detected as html5 (avoiding any browser-specific legacy fallback modes). So you couldn't have a <g> element as the root if you use an html5 parser.

这篇关于在IE9中,导入的节点似乎没有被识别为SVG元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆