Alex Rivera | Logout

Best way to pretty print XML response in grails

Asked 2008-10-23T21:50:49.127
11

Given this in a grails action:

def xml = {
    rss(version: '2.0') {
        ...
    }
}
render(contentType: 'application/rss+xml', xml)

I see this:

<rss><channel><title></title><description></description><link></link><item></item></channel></rss>

Is there an easy way to pretty print the XML? Something built into the render method, perhaps?

Edit
Report

1 Answer

3

Use MarkupBuilder to pretty-print your Groovy xml

def writer = new StringWriter()
def xml = new MarkupBuilder (writer)

xml.rss(version: '2.0') {
        ...
    }
}

render(contentType: 'application/rss+xml', writer.toString())
answered 2011-06-13T05:02:13.050

Your Answer