I have been trying to render a simple XML file from a Grails Controller and I’ve found tons of blogs that provided the most complicated examples or examples that were too basic. After much tinkering around this is the code that will generate an XML file in the following format based on the items contained in the list.
<resultset>
<result>happy</result>
<result>sad</result>
<result>angry</result>
</resultset>
inside the Controller action...
def finalList = ['happy', 'sad', 'angry']
render(contentType: 'application/xml') {
resultSet(){
finalList.each { item ->
result(item)
}
}
}