I want to check if a certain xml tag exists in a file, and do something if it does and something else if it doesn't exist.
I am iterating through the file like this:
def root = new XmlSlurper().parseText(xml)
root.node.each { node ->
println "found node"
}
So how do I make some kind of "else" bracket which executes if the node doesn't exist?
(The XML file is big and consists of many different tags. I want to know if a specific tag exists. In this example the 'node' tag)
One way of doing the same would be:
boolean exists = false
def root = new XmlSlurper().parseText(xml)
root.node.each { node ->
exists = true
println "found node"
}
if(exists) {
// do something
}
Can it be done more elegant?