我最近一直在使用XPath,并一直在寻找有关哪些浏览器支持XPath 2.0而没有太多运气的信息.我能找到的最好的是各种渲染引擎的查询技术比较表.
这清楚地告诉我Firefox和IE(两者的所有版本)都不支持XPath 2.0,但是Chrome,Safari等的其他渲染引擎呢?有没有人有这方面的信息或知道哪里可以找到它?
我的印象是所有最新的浏览器现在都使用XPath 2.当我使用lower-case()和uppser-case()(版本2中引入的功能)时,Chrome会抛出语法错误.然而,他们较旧的替代品translate()工作正常.
这是一个错误还是最新的Chrome实际上使用XPath 1?是否有命令/方法来找出XPath版本?
// Finds the element as expected.
$x('//h2/text()[. = "Delete"]')
// Doesn't find the element (also expected).
$x('//h2/text()[. = "delete"]')
// SyntaxError: Failed to execute 'evaluate' on 'Document': The string '//h2/text()[lower-case(.) = "delete"]' is not a valid XPath expression.
$x('//h2/text()[lower-case(.) = "delete"]')
Run Code Online (Sandbox Code Playgroud) 有谁知道在XML :: LibMXL中实现了哪个版本的XPath规范?
或者更重要的是,在哪里可以找到我可以在LibXML中使用的XPath函数的描述?
例如,我尝试过类似的东西
$dcDOM->findvalue('//dc:identifier[contains(@xsi:type,"URI")]');
Run Code Online (Sandbox Code Playgroud)
这看起来很好,但是
$dcDOM->findvalue('//dc:identifier[matches(@xsi:type,"URI")]');
Run Code Online (Sandbox Code Playgroud)
才不是.
从那一点开始,我们必须假设它最多支持XPath 1.0或1.0/2.0的某个子集.
是否有一个整洁的页面列出和描述了所有内容?
当我们看到一致性图表时,例如https://caniuse.com/#search=xpath和https://developer.microsoft.com/en-us/microsoft-edge/platform/status/domlevel3xpath/?q=xpath,它通常是关于DOM Level 3 XPath 的,重点是使用 XPath 1.0访问 DOM 对象,但不一定是 XPath 3.0 或更高版本。
问题 1 - W3C 等对浏览器是否有明确的版本要求以支持较新版本的 XPath?
此 XPath 1.0 功能有效:
document.evaluate(
'normalize-space(" X ")',
document, null, XPathResult.ANY_TYPE, null ).stringValue
// => "X"
Run Code Online (Sandbox Code Playgroud)
但是这个 XPath 3.0 内联函数功能 ( ref ) 会抛出:
document.evaluate(
'let $incr := function($n as xs:integer) as xs:integer { $n +1 } return $incr(2)',
document, null, XPathResult.ANY_TYPE, null ).stringValue
Run Code Online (Sandbox Code Playgroud)
边缘:
XPATH15001:不支持 XPath 查询“let $incr := function($n as xs:integer) as xs:integer …
xpath ×4
xml ×3
browser ×1
dom ×1
javascript ×1
libxml2 ×1
perl ×1
selenium ×1
xml-parsing ×1
xpath-2.0 ×1