2
Groovy的MarkupBuilder有omitNullAttributes
和omitEmptyAttributes
。但DOMBuilder不。这是我的代码用groovy省略空属性DOMBuilder
>>> def xml = DOMBuilder.newInstance()
>>> def maybeEmpty = null
>>> println xml.foo(bar: maybeEmpty)
<foo bar=""/>
我想bar
如果为空,则省略。我在Groovy AntBuilder, omit conditional attributes...至findAll
空属性的答案中找到解决方法并将其删除。由于我有一个复杂的DOM生成,我正在寻找其他选项。