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

前端 未结 3 958
一个人的身影
一个人的身影 2020-12-14 19:25

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

I need to find all car elements in this document:



        
3条回答
  •  隐瞒了意图╮
    2020-12-14 19:45

    This is how it works:

    def xml = new XmlSlurper().parse(file)
    def cars = xml.depthFirst().findAll { it.name() == 'car' }
    assert cars.size() == 2
    

提交回复
热议问题