英文:
MarkupBuilder - Generate attributes without encapsulation
问题
以下是您要翻译的部分:
但它生成了:
<consolidate amount="220.36" date="2023-01-06" invoiceId="123456XXX" currency="EUR" />
</consolidate>
而期望的是:
<consolidate amount=220.36 date="2023-01-06" invoiceId="123456XXX" currency="EUR" />
</consolidate>
英文:
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>
答案1
得分: 1
你标记为“expected”的结果不是有效的XML(可以使用验证器进行检查)。属性的值必须始终用引号括起来:
> 属性值必须始终用引号括起来。可以使用单引号或双引号。
请参阅此处了解更多信息。
由于这个原因,你不应该,也可能无法使MarkupBuilder
生成所期望的结果。
英文:
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:
> Attribute values must always be quoted. Either single or double quotes
> can be used.
See more here.
For that reason you shouldn't and probably can't make MarkupBuilder
to produce the desired result.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论