Is it possible to generate attributes using MarkupBuilder() without encapsulating it. I have the following:
def writer = new StringWriter()
def xml = new MarkupBuilder(writer)
// generate strings with double quotes
xml.setDoubleQuotes(true);
invoiceId = "123456XXX";
date = "2023-01-06";
amount = 220.36;
xml.consolidate(amount:amount.toDouble(),
date: date,
invoiceId: invoiceId,
currency:'EUR');
}
but it generates:
<consolidate amount="220.36" date="2023-01-06" invoiceId="123456XXX" currency="EUR" />
</consolidate>
when the following is expected:
<consolidate amount=220.36 date="2023-01-06" invoiceId="123456XXX" currency="EUR" />
</consolidate>
The result that you put as "expected" is not a valid XML (you may check it with the validator). The attribute's value is always quoted:
See more here.
For that reason you shouldn't and probably can't make
MarkupBuilderto produce the desired result.