Gico
Gico

Reputation: 1394

Process XML with inline groovy script

I would like to prepare sample XML files with dynamic content. I am interesting in a way to put a groovy code (or any other script language) inside XML file and to process it to get a XML file populated with values that results inline scripts.

for example:

<myXmldata>
     <node>testSample ${=new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new Date())}</node>
</myXmldata>

and after the file would be processed i would get:

<myXmldata>
  <node>testSample 20150326140122</node>
</myXmldata>`

I saw something similar in SoapUI and in maven scripts, but i do not know how to "execute" such a file.

Many thanks!

Upvotes: 0

Views: 346

Answers (1)

Opal
Opal

Reputation: 84844

In the simplest case:

#!/usr/bin/env groovy

println(
"""
<myXmldata>
     <node>testSample ${new java.text.SimpleDateFormat("yyyyMMddHHmmss").format(new Date())}</node>
</myXmldata>
"""
)

Have a look at templates - it might be what you are looking for.

Upvotes: 2

Related Questions