javascript - 浏览器中的 XPath 3

标签 javascript xml dom xpath browser

当我们看到一致性图表时,比如https://caniuse.com/#search=xpathhttps://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"

但是这个 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

边缘:

XPATH15001: XPath query "let $incr := function($n as xs:integer) as xs:integer { $n +1 } return $incr(2)" not supported

火狐:

SyntaxError: The expression is not a legal expression.

问题 2 - 如果浏览器允许 XPath 3.0,假设我的代码中存在错误;那么 v3.1 功能(例如 arrow-functions )是否也被允许?

最佳答案

No browsers support XPath 2.0 natively ,更不用说 XPath 3.0 了。

另请注意 XPath, unlike XSLT, doesn't have an intrinsic way of determining the version of an XPath implementation除了像您所做的那样尝试给定版本支持的功能并观察是否发生错误。

关于javascript - 浏览器中的 XPath 3,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48043476/

相关文章:

javascript - JS Accordion 未打开

javascript - 为什么这个指向 JS 文件的链接返回未经授权,但它在 HTML 中有效?

java - 如何使用返回 HTTP 301 的架构 URL 验证 XML?

javascript - 如何在文本区域中只允许退格和移动

javascript - 插入span-node,继续写

html - 如何使用 Web::Scraper 解析此 HTML?

javascript - 只返回与时间无关的日期javascript

javascript - 在 NodeJS 上添加异步函数时出现错误

xml - Delphi XML Bindings 对象 - 导出节点

node.js - 根据接收器文件中的条件填充 Node