I want to make the following changes in the xml file
My test.xml
Some Name
....
&l
After going through the Node (Groovy 2.4.6) I came up with this
task ("replace")<<{
xmlSource = file(path/to/xml source file)
xmlDest = file(path/to/destinationfile)
def parser = new XmlParser()
def xmlRoot = parser.parse(xmlSource)
xmlRoot.each{
if(it.name().equals("resource-ref")&& it.@id.equals("change")){
it.'resource-name'[0].value = 'After Change'
}
else if(it.name().equals("resource-ref")&& it.@id.equals("modify")){
it.'resource-name'[0].value = 'After Modify'
}
}
def b = new XmlNodePrinter(new PrintWriter(new FileWriter(xmlDest)))
b.preserveWhitespace = true
b.print(z)
}
Not sure if its the best way. But it works