I would like to insert comments into my xml document with a Groovy MarkupBuilder. How is it possible?
You can use mkp.comment
like so:
def writer = new StringWriter()
def builder = new groovy.xml.MarkupBuilder( writer )
builder.cars {
mkp.comment "A comment"
ford( type:'escort')
ford( type:'fiesta')
}
println writer
Which prints:
<cars><!-- A comment -->
<ford type='escort' />
<ford type='fiesta' />
</cars>
The mkp.XXX
methods are described here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With