views:

30

answers:

2

I would like to insert comments into my xml document with a Groovy MarkupBuilder. How is it possible?

+1  A: 

Try MarkupBuilderHelper.comment(). The linked page has an example.

Uses getMkp() to get the MarkupBuilderHelper.

LarsH
+5  A: 

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

tim_yates
thank you tim, it works!
jabal