的XPath表达式在Microsoft

的XPath表达式在Microsoft

本文介绍了使用“和"的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返回正确的节点.只有当这两个条件(对于所讨论的节点都适用)与and组合时,它才会失败.我绝不是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中 current 实现的一个错误.但是,我确实注意到,如果您翻转条件,则会检索适当的元素:

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']

暂时,我希望这是可以接受的替代方法.我正在为我们的团队打开一个bug,以供我们审查.非常感谢您帮助我们改进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 :)

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

1403页,肝出来的..

09-06 12:40