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



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

how can find elements in xml tag name in groovy (gpath)?

i need find car elements in document:

<records> <first> <car><id>378932<id></car> </first> <second> <foo> <car><name>audi</name></car> </foo> </second> </records>

this tried , failed:

def xml = new xmlslurper().parse(file) assert xml.car.size() == 2

this how works:

def xml = new xmlslurper().parse(file) def cars = xml.depthfirst().findall { it.name() == 'car' } assert cars.size() == 2

xml groovy

Comments

Popular posts from this blog

c# - Move local mssql database to webhosted MYSQL -

java - How to pass parameters between Request-Scoped Controllers? -

string - what is the difference between "some" == "some\0" and strcmp("some","some\0") in c++? -