How to select node which has a parent with some attributes. Eg: what is Xpath to select all expiration_time elements. In the following XML, I'm getting error if states elements has attributes, otherwise no probs.
Thanks
<lifecycle>
<states elem="0">
<expiration_time at="rib" zing="chack">08</expiration_time>
</states>
<states elem="1">
<expiration_time at="but">4:52</expiration_time>
</states>
<states elem="2">
<expiration_time at="ute">05:40:15</expiration_time>
</states>
<states elem="3">
<expiration_time>00:00:00</expiration_time>
</states>
</lifecycle>
states/expiration_time[../@elem = "0"]
?
Use:
/*/*/expiration_time
This selects all expiration_time
elements that are grand-children of the top-element of the XML document.
/*/*[@*]/expiration_time
This selects any expiration_time
element whose parent has at least one attribute and is a child of the top element of the XML document.
/*/*[not(@*)]/expiration_time
This selects any expiration_time
element whose parent has no attributes and is a child of the top element of the XML document.
/*/*[@elem = '2']/expiration_time
This selects any expiration_time
element whose parent has an elem
attribute with string value '2' and that is (the parent) a child of the top element of the XML document.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With