I have a large number of XML files that contain URLs. I\'m writing a groovy utility to find each URL and replace it with an updated version.
Given example.xml:
I just created gist at: https://gist.github.com/akhikhl/8070808 to demonstrate how such transformation is done with Groovy and JDOM2.
Important notes:
Update
The following code:
new XMLOutputter().with {
format = Format.getRawFormat()
format.setLineSeparator(LineSeparator.NONE)
output(doc, System.out)
}
solves a problem with preserving whitespaces and line separators. getRawFormat constructs a format object that preserves whitespaces. LineSeparator.NONE instructs format object, that it should not convert line separators.
The gist mentioned above contains this new code as well.