How to select a node that has a parent with some attributes

How to select a node that has a parent with some attributes. For example: what is the Xpath for selecting all expiration_time elements. In the following XML, I get an error if the state elements have attributes, otherwise there is no problem.

thank

<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>
+5
source share
3 answers

states/expiration_time[../@elem = "0"]?

+4
source

Using

/*/*/expiration_time

This selects all elements expiration_timethat are grand children of the top element of the XML document.

/*/*[@*]/expiration_time

This selects any element expiration_timewhose parent element has at least one attribute and is a child of the top element of the XML document.

/*/*[not(@*)]/expiration_time

expiration_time, XML.

/*/*[@elem = '2']/expiration_time

expiration_time, elem "2", () XML.

+3

This will give you all nodes having at least one attribute

//*[count(./@*) &gt; 0]
0
source

All Articles