Thanks Tommy,
My problem was in the context of a custom ant task. I found that if I let
go of the idea of "arbitrary additional content" and defined what the
different additional sections could be, it was quite easy to do. My
solution is here:
https://github.com/Alipsa/uso/blob/main/uso-tasks/src/main/groovy/se/alipsa/uso/tasks/CreatePom.groovy
in case anyone is interested.

Best regards,
Per

On Mon, 19 May 2025 at 14:01, <to...@natusoft.se> wrote:

> Hello Per,
>
> I don't know of anything existing that does what you want. But, in Groovy
> you can easily define structures like JSON or XML (which both give you a
> structure but does so using different formats.
>
> Example: Map<String, Object> root = [ "id": "QAZ",  "name" : "Nisse", ... ]
>
> This is a java.util.Map structure. Your code can then take this
> Map<String, Object> and convert to JSON or XML. But I don't know of
> anything existing that takes such a Map structure to XML. I would not be
> entirely surprised if such exists.
>
> In my current project I'm using the Groovy Map shortcut [ : ] to build
> structured information. In my case it will be converted to JSON and
> potentially other structured formats later.  But as long as you have the
> information stored in some structured way it should be relatively easy to
> convert to XML. Reading both JSON and XML is by far more difficult than
> producing them.
>
> Best Regards,
>
> Tommy Svensson
> On 18 May 2025 at 20:38 +0200, Per Nyfelt <p...@alipsa.se>, wrote:
>
> 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
>
>

Reply via email to