You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@groovy.apache.org by Reinhard Torsten <To...@nttdata.com> on 2016/03/08 19:22:31 UTC
XmlTemplateEngine - output format
Hi,
I´m using the XmlTemplateEngine to generate some config files using the following code:
XmlTemplateEngine engine = new XmlTemplateEngine()
Template template = engine.createTemplate( getTemplateFile() )
Writable output = template.make( getConfig() )
StringWriter writer = new StringWriter()
output.writeTo(writer)
println writer.toString()
The generated output looks like:
...
<configversion>
20150903
</configversion>
...
But it should´nt have whitespaces, so this is what I want:
<configversion>20150903</configversion>
My current workaround is to parse the result again and re-format it using
xmlNodePrinter = new XmlNodePrinter()
xmlNodePrinter.with {
preserveWhitespace = true
expandEmptyElements = true
quote = "'" // Use single quote for attributes
}
xmlNodePrinter.print( new XmlParser().parseText(writer.toString() ))
ð How can I easily adjust the output format of the generated *.xml without re-reading it?
Thanx for any help
Torsten
______________________________________________________________________
Disclaimer: This email and any attachments are sent in strictest confidence
for the sole use of the addressee and may contain legally privileged,
confidential, and proprietary data. If you are not the intended recipient,
please advise the sender by replying promptly to this email and then delete
and destroy this email and any attachments without any further use, copying
or forwarding.