groovy-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Reinhard Torsten <Torsten.Reinhard...@nttdata.com>
Subject XmlTemplateEngine - output format
Date Tue, 08 Mar 2016 18:22:31 GMT
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.
Mime
View raw message