When I had the above case described, I just set the Boolean var found1item to true and, finding the next element, I checked this element and set found1item to false again. If you have a deeper investment, it can be difficult to implement, but if it is only nested, once it is simple.
source
share