doc.evaluate的替代品

A substitute for doc.evaluate

本文关键字:替代品 evaluate doc      更新时间:2023-09-26

是否有任何更短的表达式可以通过XPath获得DOM点头,从需要大量变量的以下命令更简洁。

doc.evaluate(xpath, doc, nsResolver, XPathResult.ANY_TYPE, null);  

据我所知,Firefox 只支持 DOM Level 3 XPath API,其中一部分是 evaluate 函数。如果你想要更短的东西,那么你需要自己滚动(或找到一个为你做的库),或者你需要使用不同的浏览器,例如使用Opera,你可以这样做,例如 node.selectSingleNode(path [,nsResolver])选择单个节点,node.selectNodes(path [, nsResolver])可以选择节点的 DOM 节点列表。在MSXML的XML DOM实现中,你与IE一起使用,你也有selectSingleNodeselectNodes函数,尽管命名空间处理与Opera实现不同,因为MSXML你需要使用document.setProperty('SelectionNamespaces', 'xmlns:pf1="http://example.com/ns1" xmlns:pf2="http://example.com/ns2"')