单个 xpath 表达式获取一些属性

发布于 2024-10-01 17:41:07 字数 205 浏览 0 评论 0原文

我有一个包含一些节点的 XML 文档,例如

<node name="xxx" id="xxx">

Can I use a single XPath expression to get all attribute Nodes hisparent has atrtribute @id = 7?

I have an XML document with some nodes like

<node name="xxx" id="xxx">

Can I use a single XPath expression to get all attribute nodes whose parent has also atrtribute @id = 7?

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

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

发布评论

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

评论(3

梦巷 2024-10-08 17:41:07

使用

//@*[not(name()='id') and ../@id = 7]

选择所有非 id 属性,其父级具有值为数字 7id 属性。这将接受 id='7'id=' 7 '

//@*[not(name()='id') and ../@id = '7']

这会选择其父级具有 id 属性值的所有非 id 属性字符串'7'。这将接受 id='7' 但不接受 id='7'

Use:

//@*[not(name()='id') and ../@id = 7]

this selects all non-id attributes whose parent has an id attribute with value the number 7. this will accept id='7' and id=' 7 '

//@*[not(name()='id') and ../@id = '7']

this selects all non-id attributes whose parent has an id attribute with value the string '7'. This will accept id='7' but not id=' 7 '

瘫痪情歌 2024-10-08 17:41:07

不可以。您需要一一定义要读出的属性。

/node[@id=7]/@name 

将获取 name

/node[@id=7]/@id

将获取 id

等。

No. You will need to define which attribute to read out - one by one.

/node[@id=7]/@name 

will get the name

/node[@id=7]/@id

will get the id

etc.

匿名的好友 2024-10-08 17:41:07

这将选择所有值为 7 的 id attribute 节点:

//*/@id[. = '7']

This will select all id attribute nodes that have the value 7:

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