1

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

Миша Кошелев
  • 1,483
  • 1
  • 24
  • 41

1 Answers1

2

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
  • 2,592
  • 19
  • 23