Internet Explorer中的DOM Level 3 XPath [英] DOM Level 3 XPath in Internet Explorer

查看:210
本文介绍了Internet Explorer中的DOM Level 3 XPath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在我的Windows 7上安装了IE10,我注意到,即使我很高兴来自AJAX请求的XML现在是兼容的DOM文档,一个相当基本的功能,如 document.evaluate 不支持

I just installed IE10 on my Windows 7, and I've noticed that, even if I'm glad that XMLs from AJAX requests are now compatible DOM documents, a rather basic function like document.evaluate is still not supported.

更糟糕的是,因为这些XML 自定义Microsoft IXMLDocument 对象,节点不支持 selectNodes selectSingleNode 了。 最后,似乎IE10不支持DOM Level 3 XPath或MSXML Xpath。

What's worse is that, since those XMLs are not the custom Microsoft IXMLDocument objects, the nodes don't support selectNodes and selectSingleNode anymore. In the end, it seems that IE10 does not support DOM Level 3 XPath or MSXML Xpath.

说真的,微软?有什么东西我不见了吗?

Seriously, Microsoft? Is there something I'm missing?

当然,我可以使用 querySelector querySelectorAll ,但我不想失去相当多的向后兼容性。

Sure, I can use querySelector and querySelectorAll, but I don't want to lose quite a bit of backward compatibility.

否则,仍然可以使用此行请求MSXML文档

Otherwise, one can still request a MSXML document using this line

try {xhr.responseType = "msxml-document";} catch(e) {}

如上所述这里,但我认为最好是处理标准会很好IE中的DOM文档也是如此。

as stated here, but I think it would be nice to deal with, at last, a standard DOM document in IE too.

那么,有没有办法在IE10中使用带有标准DOM文档的XPath?

So, is there a way to use XPath in IE10 with standard DOM documents?

更新2013年6月26日 IE11尚不稳定,但仍然不支持 document.evaluate 。如果它不能在稳定版本中支持它,我怀疑它将支持它。毋庸置疑,这是荒谬的。

UPDATE 26/7/2013 IE11 isn't stable yet, but it still doesn't support document.evaluate. If it won't support it in the stable release, I doubt it will ever support it. Needless to say this is ridicolous.

我知道你可以使用 querySelector / 全部在DOM节点中,但它在IE9及更低版本中不受支持,这仍然是非常常用的,无论如何XPath比选择器更强大。

I get that you can use querySelector/All in DOM nodes, but it's not supported in IE9 and lower, which are still quite commonly used, and anyway XPath is more powerful than selectors.

幸运的是(如果你可以这么说),你仍然可以设置 xhr.responseType =msxml-document。有一刻我担心你再也不能这样做了......

Fortunately (if you can say that), you can still set xhr.responseType = "msxml-document". For a moment I feared you couldn't do that anymore...

更新23/11/2013 IE11现在稳定但很遗憾,它不支持 document.evaluate 。随着重量级XML文档在Web应用程序中的使用越来越少,支持JSON或其他轻量级符号格式,这种问题变得越来越少,但仍然存在。

UPDATE 23/11/2013 IE11 is stable now but, sadly, it doesn't support document.evaluate. As heavy-weight XML documents are used less and less in web applications in favor of JSON or other light notation formats, this is becoming less of a problem, but still.

设置 responseType 属性仍然提供遗留XML文档,因此我猜不会丢失任何内容。我不知道IE12是否能保持这种状态。

Setting the responseType property still provides legacy XML documents, so nothing is lost I guess. I don't know if that will stay true for IE12, though.

更新15/8/2015 现在听起来很荒谬,但Edge现在支持 document.evaluate 。就在(几乎)一切都切换到JSON进行数据交换时。嗯,迟到总比没有好,我想。

UPDATE 15/8/2015 Sounds ridiculous right now, but Edge now supports document.evaluate. Just when (almost) everything switched to JSON for data exchange. Well, better late than never, I guess.

推荐答案

是的,IE中还没有XPath支持= /。

Yes, there's still no XPath support in IE =/.

对我来说,遗憾的是,在每个浏览器中使用 document.evaluate 的最可靠方式是通过库。

For me, the most reliable way to use document.evaluate in every browser is, sadly, via a library.

它被称为 Wicked Good XPath ,这是最近谷歌撰写的旧版 JavaScript-XPath 库。自发布以来,我一直在使用Wicked Good XPath,并且对它非常满意(好吧,不如使用本机XPath支持,但仍然如此)。

It's called Wicked Good XPath and it's a recent Google-authored rewrite of the old good JavaScript-XPath library. I've been using Wicked Good XPath since the release and have been really comfortable with it (well, not as much as with a native XPath support, but still).

这篇关于Internet Explorer中的DOM Level 3 XPath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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