XPath:如何:选择具有当前上下文的给定属性名称的所有子项和孙项(无论深度如何)?
xml:
<root0>
<elem1>
<elem21 xlink:href="21"/>
<elem22>
<elem31 xlink:href="31"/>
<elem32>
<elem41 xlink:href="41"/>
</elem32>
</elem22>
</elem1>
</root0>
深度未知。如何选择具有 xlink:href 属性的所有元素?
我尝试了以下方法:
*[@xlink:href]
self::*[@xlink:href]
感谢任何指导。
xml:
<root0>
<elem1>
<elem21 xlink:href="21"/>
<elem22>
<elem31 xlink:href="31"/>
<elem32>
<elem41 xlink:href="41"/>
</elem32>
</elem22>
</elem1>
</root0>
the depth is unknown. How can I select all elements with xlink:href attribute?
I tried the following:
*[@xlink:href]
self::*[@xlink:href]
Any guidance is appreciated.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于孙子的孩子使用
对于所有节点,只需在 xpath 前面添加 //
另外,您的 xml 示例无效,但我猜它只是一个示例。
For just children of grandchildren use
For all nodes just add // in front of your xpath
Also, your xml sample is not valid but I'm guessing it is just a sample.
*[@xlink:href]
应该可以工作。您很可能尚未定义xlink
命名空间。如果您发布代码,那么我的回答可以更准确。
*[@xlink:href]
should work. It is most likely that you have not defined thexlink
namespace.If you post the code, then I can be more precise in my answer.