[英]Xpath how to use and statement and parent condition on a node selection
假设我有这样的XML:
<my-parent-tag attr="">
<my-child-tag/>
</my-parent-tag>
<my-child-tag/> <!--I don't want to select this one-->
我想找到所有具有父节点my-parent-tag和attr =“”的my-child-tag。 如何在Xpath中表达这一点? 我试过了
//my-child-tag and [../my-parent-tag[@attr='']]
但是,我最终收到了Xpath-no-node-selected反馈。 感谢帮助:)
为什么不只使用正则表达式//parent/child
从具有属性的父对象中选择所有后代标签:
//my-parent-tag[@attr='']//my-child-tag
从具有属性的父对象中选择所有子标记:
//my-parent-tag[@attr='']/my-child-tag
您可以使用//my-child-tag[parent::my-parent-tag[@attr='']]
这个XPath
//my-parent-tag[@attr='']/my-child-tag
将选择所有my-child-tag
用的父元素my-parent-tag
具有attr
的属性值''
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.