Given the following tricky XML:
<Type>
<ID></ID>
<Name></Name>
<Child>
<Type>
<ID></ID>
<Name></Name>
<Child>
<Type>
<ID></ID>
<Name></Name>
<Child>
<Type>
<ID></ID>
<Name></Name>
<Child>
<Type>
<ID></ID>
<Name>FIND ME</Name>
</Type>
</Child>
</Type>
</Child>
</Type>
</Child>
</Type>
</Child>
</Type>
Is it possible to obtains the deepest Type’s Name field? I’ve tried constructions like that:
//*not(*)
but with no results..
I. This short and simple XPath 1.0 expression:
when evaluated against the provided XML document:
selects these two elements:
Therefore, in your case one XPath expression that produces the wanted result is:
II. Generic XPath 1.0 expression that selects the elements with maximum depth when it is known that the maximum depth isn’t greater than a given number:
While this seems a very long and unwieldy, an XML document typically is not more than 4-5 level deep and such expression is actually practical.
III. Generic XPath 2.0 solution: