views:

25

answers:

1

Its a Grails app and we'd like to be able to add XML namespaces to the xml produced for REST clients. Most of the xml is output using "render foo as XML" with the deep converter.

So the output needs to be something like: <foo xmlns:myns='http://mycompany.com/myproduct/ver'&gt; ... </foo>

A: 

http://groovy.codehaus.org/Creating+XML+using+Groovy%27s+MarkupBuilder

def xml = new MarkupBuilder(writer)
xml.'rec:records'('xmlns:rec': 'http://groovy.codehaus.org') {
  car(name:'HSV Maloo', make:'Holden', year:2006) {
    country('Australia')
    record(type:'speed', ' Truck with speed of 271kph')
  }
}

result

<rec:records xmlns:rec='http://groovy.codehaus.org'&gt;
  <car name='HSV Maloo' make='Holden' year='2006'>
    <country>Australia</country>
    <record type='speed'> Truck with speed of 271kph</record>
  </car>
</rec:records>
Aaron Saunders
Thanks for the reply, Aaron. We are using the "render foo as XML" construct, so how do we use the MarkupBuilder in this context? It's too much work to go to a manual serialization process in our case.
Sunny
grails does not support it through the standard converters, see bug http://jira.codehaus.org/browse/GRAILS-5152
Aaron Saunders