将简单的 XPath 查询转换为 E4X 查询

发布于 2024-08-16 12:06:58 字数 239 浏览 8 评论 0原文

人们可能会认为 XPath 查询的相应 E4X 查询 //*[@foo = "bar"] 将是 ..*.(@foo == "bar")< /code>,但是每当它到达没有 foo 属性的元素时就会抛出错误。我目前正在使用 ..*.(function::valueOf().@foo == "bar") 代替。

我的问题是是否有另一种更简单的方法来做到这一点。

One might think the corresponding E4X query for the XPath query, //*[@foo = "bar"], would be ..*.(@foo == "bar"), but that will throw an error whenever it gets to an element without a foo attribute. I am currently using ..*.(function::valueOf().@foo == "bar") instead.

My question is if there is another, less of a hack-way to do this.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不寐倦长更 2024-08-23 12:06:58

稍微不那么hacky的方法可能是使用attribute函数:

..*.(function::attribute("foo") == "bar")

little bit less hacky way might be using the attribute function:

..*.(function::attribute("foo") == "bar")

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文