Greasemonkey:XPath对.xhtml页面不返回任何结果 [英] Greasemonkey: XPath returns no results for .xhtml page
本文介绍了Greasemonkey:XPath对.xhtml页面不返回任何结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在xhtml页面上运行时,xpath似乎不会返回任何结果.
When running on an xhtml page, xpath doesn't seem to return any results.
var result = document.evaluate( "//a/img", document.body, null, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
例如,返回空结果集.这是什么问题,我该如何解决?
For example returns an empty result set. What's the problem here, and how do I fix it?
推荐答案
xhtml elements are not in null namespace, so you have to pass a namespace resolver to the method:
function resolver(prefix) {
return prefix === 'x' ? 'http://www.w3.org/1999/xhtml' : null;
}
var result = document.evaluate( "//x:a/x:img", document.body, resolver, XPathResult.ORDERED_NODE_SNAPSHOT_TYPE, null );
这篇关于Greasemonkey:XPath对.xhtml页面不返回任何结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文