Using MarkupBuilder as a closure argument

Per Nyfelt <[email protected]> Sun, 18 May 2025 20:38:28 +0200
Newsgroups gmane.comp.lang.groovy.user
Organization Alipsa HB
Message-ID <[email protected]>
Hi,

I would like to have a user api that can handle the following:

createXml(target: xmlFile, name: 'a test') {

     description('test xml')

     licenses {
         license('Apache License, Version 2.0', 
'http://www.apache.org/licenses/LICENSE-2.0')
     }

}

// description and licenses are arbitrary, it can be any structure that 
can be converted to XML

I want the closure to behave as if it would be statements to a 
MarkupBuilder but I am unable to figure out how to do it. Can i convert 
the closure to a MarkupBuilder or process it with a MarkupBuilder 
somehow? Any ideas?

Best regards

Per