I'm trying to use Groovy MarkupBuilder to dynamically create my custom XML structure like below.
<envelope>
<header>
<key1>value1</key1>
</header>
<body>
<payload />
</body>
</envelope>
Though I got it working with the below code, I would like inject the 'payload' part of the code dynamically in a separate class where the 'builder' is passed in as a method parameter.
def writer = new StringWriter()
def builder = new MarkupBuilder(writer)
builder.envelope{
header{
key1("value1")
}
body{
payload(){
}
}
}
println writer.toString()
Is that what You're looking for?