yegor256 yegor256 - 1 year ago 146
Groovy Question

How to find all XML elements by tag name in Groovy?

How I can find all elements in XML by their tag name in Groovy (GPath)?

I need to find all

elements in this document:


This is what I tried and failed:

def xml = new XmlSlurper().parse(file)
assert == 2

Answer Source

This is how it works:

def xml = new XmlSlurper().parse(file)
def cars = xml.depthFirst().findAll { == 'car' }
assert cars.size() == 2
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download