Adding dynamic elements and attributes to groovy MarkupBuilder or StreamingMarkupBuilder [closed]
A map with the attribute names as keys should do it. You need to wrap the key in braces so that Groovy knows you mean to use the value of a
rather than the key a
:
import groovy.xml.MarkupBuildernew MarkupBuilder().root { def a = 'dynAttr' node( [ (a):'woo' ] )}
Would generate:
<root> <node dynAttr='woo' /></root>