This is my Groovy code:
// ...
def xml = new XmlParser().parse(fileName)
xml.each { e ->
// some changes are being made to XML
xml.append("test", "test me")
}
def writer = new FileWriter(newFileName)
new XmlNodePrinter(new PrintWriter(writer)).print(xml)
The code works, but the output XML has a lot of unnecessary white spaces. Looks like I'm doing something wrong with writing to file.
ps. Thanks to Tim, this is how it should work (the last line of the example above shall be replaced with these three lines):
def printer = new XmlNodePrinter(new PrintWriter(writer))
printer.preserveWhitespace = true
printer.print(xml)