使用“and"的 XPath 表达式在 Microsoft Edge 中不起作用? [英] XPath expression using "and" doesn't work in Microsoft Edge?

查看:70
本文介绍了使用“and"的 XPath 表达式在 Microsoft Edge 中不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个应用程序,该应用程序使用 XPath 表达式从 XML 中选择节点.我们已经注意到,在 Microsoft Edge 预览版中进行测试时,这对我们来说似乎崩溃了.我已将我们的代码缩减为一个简短的片段来演示该问题:

I'm working on an application that uses XPath expressions to select nodes from XML. We've noticed that this seems to break down for us when testing in the Microsoft Edge preview. I've cut down our code to a brief snippet that demonstrates the issue:

var xml = "<xml id='relationships'><Relationships><f id='some_id' ><f id='some_other_id' /></f></Relationships></xml>";
var doc = (new DOMParser).parseFromString(xml, "text/xml");
var nodes = doc.evaluate("//f[@id='some_id' and f]", doc, doc.createNSResolver(doc.documentElement), XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null);
console.log(nodes.snapshotLength);

在 Chrome 中,这将注销 1 并且 nodes.snapshotItem 将包含正确的节点,但在 Edge 中,它将注销 0 并且不返回任何节点.

In Chrome, this will log out 1 and the nodes.snapshotItem will contain the correct node, but in Edge, it's logging out 0 and returning no nodes.

如果我单独运行这个条件的任何一半,"//f[@id='some_id']""//f[f]",它在浏览器中始终如一地工作,Edge 返回正确的节点.只有当这两个条件(对于所讨论的节点都为真)与 结合时,它才会失败.我无论如何都不是 XPath 专家,所以谁能告诉我我是否在此代码段中做了任何非标准的事情,或者这看起来像是 Edge 预览版的 XPath 实现的问题?

If I run either half of this condition separately, "//f[@id='some_id']" or "//f[f]", it works consistently across browsers and Edge returns the correct node. It only fails when these two conditions, both true for the node in question, are combined with the and. I'm not an XPath expert by any stretch, so can anyone tell me if I'm doing anything nonstandard within this snippet, or if this looks like an issue with the Edge preview's XPath implementation?

推荐答案

更新:此问题已在 2015 年 11 月的 Windows/Edge 更新中得到解决

这似乎是 Microsoft Edge 中当前实现的一个错误.但是,我确实注意到,如果您翻转条件,则会检索到正确的元素:

This appears to be a bug with the current implementation in Microsoft Edge. I did notice, however, that if you flip the conditions around, the proper element is retrieved:

//f[f and @id='some_id']

就目前而言,我希望这是一个可以接受的替代方案.我正在为我们的团队打开一个错误,以便我们进行审查.感谢您帮助我们改进 Microsoft Edge :)

For the time being, I hope this is an acceptable alternative. I am opening up a bug for our team to review on our end. Than you for helping us improve Microsoft Edge :)

这篇关于使用“and"的 XPath 表达式在 Microsoft Edge 中不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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