Jonas Praem
Jonas Praem

Reputation: 2454

How to acces parent XML element

I am iterating an XML file like this:

new XmlSlurper().parseText(getServiceConfigXml())
            .'**'
            .findAll { it.name() == 'something' }
            .each { node ->

println "attribute: ${node.attributes()} and body: ${node.text()}"
}

How can i acces the parent element of 'node' ?

Upvotes: 2

Views: 1939

Answers (1)

Jonas Praem
Jonas Praem

Reputation: 2454

${node.parent().attributes()}

you can even do

${node.parent().parent().attributes()}

to access the parent of the parent node

Upvotes: 4

Related Questions