groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Reinhard Torsten <>
Subject XmlTemplateEngine - output format
Date Tue, 08 Mar 2016 18:22:31 GMT

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()
println writer.toString()

The generated output looks like:

But it should´nt have whitespaces, so this is what I want:


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


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.
View raw message