I have gradle.build where I try:
- read xml file
- use
XmlSlurper to update an attribute in a read XML file - write the updated XML back to the originally parsed XML file.
The third step only works if I write modified XML to a new nonexistent XML file, but not to the originally parsed XML file.
What is the easiest way to write modified XML to an initially parsed XML file?
My code is:
def inFile = file('file.xml') def outFile = file('_file.xml') def xml = new XmlSlurper().parse(inFile) // update xml code here def outBuilder = new StreamingMarkupBuilder() def outWriter = outFile.newWriter() XmlUtil.serialize(outBuilder.bind{ mkp.yield xml }, outWriter)
I would like outFile be file.xml so that it overwrites the original XML file.
source share