Suppose I have a XML like this:
<my-parent-tag attr="">
<my-child-tag/>
</my-parent-tag>
<my-child-tag/> <!--I don't want to select this one-->
I want to find all my-child-tags that have the parent node my-parent-tag with attr="". How do I express this in Xpath? I tried
//my-child-tag and [../my-parent-tag[@attr='']]
But, I ended up getting Xpath-no-node-selected feedback. Help appreciated :)
Why not just use regular expression //parent/child
Selects all descendant tags from parent with attribute:
//my-parent-tag[@attr='']//my-child-tag
Selects all child tags from parent with attribute:
//my-parent-tag[@attr='']/my-child-tag
您可以使用//my-child-tag[parent::my-parent-tag[@attr='']]
This XPath,
//my-parent-tag[@attr='']/my-child-tag
will select all my-child-tag
elements with a parent of my-parent-tag
that has a attr
attribute value of ''
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.