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

前端 未结 3 959
一个人的身影
一个人的身影 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条回答
  •  旧时难觅i
    2020-12-14 19:48

    Use an XMLSlurper

    def records = new XmlSlurper().parseText(file)
    reco​rds.depthFirst()​.findAll { !it.childNodes() && it.car} ​
    
    /*Otherwise this returns the values for parent nodes as well*/
    

提交回复
热议问题