views:

35

answers:

1

Dear All:

I am using:

def idx=parent.item.children().indexOf(myElement)
if (idx+1<parent.children().size()) {
  def message=parent.children()[idx+1]
  println message.text()
}

To find the element message which is next after myelement in the parent.

However, it seems there must be a Groovier way, no?

Thank you Misha

A: 

Assuming you're trying to find all after the first one you would do this:

def messages = parent.item.children().findAll { child -> child.name() == myElement }
messages[1..-1].each { println it } 

If you wanted to just print out all messages that matched myElement

parent.item.children().findAll { child -> child.name() == myElement }.each { println it } 
stan229