A few hints ...
1) Add a XML file to override the JSON default template wit scaffolds.
Something like this:
https://gist.github.com/1583881
(this is just the default JSON format, with all json find/replace with xml).
2) Try out
$ rails generate resource User first_name:string last_name:string
to see an example in a scaffold.
Once that is there, you can start playing with localhost:3000/users.xml
to see the effect. By targeting either:
* the .xml extension in a GUI browser
* the Accept and Content-Type 'application/xml' in curl (see below)
Check the /log/development.log to verify that XML format is used (and not HTML)
3) You may override to_xml to e.g. have whitelists on what you expose over the API
(don't forget to call super in your overridden method). to_xml will be default be
used and will render a default XML template.
You can override that with a custom xml builder, like:
app/views/users/index.html.haml
app/views/users/index.xml.builder
app/views/users/show.xml.builder # here you would create your special builder for
# <SoftwareAPIResponse> if needed
But with clever includes and whitelists of associated resources, you may be
able to use the default XML template.
4) When you have associated models (e.g. User has_one :address), you will face
2 difficulties:
* address.singularize is wrong and this causes a bug in the to_xml serializer
(<user><addres>...</addres></user> with 1 's'). I will try to commit a patch
for that (in the meanwhile, use custom inflections where needed).
* for create/update accepts_nested_attributes_for will not work straightforwardly
(since it only adds e.g. user.address_attributes= ; but for XML you would need
user.address= to accept a hash and not a <Address ...> object. I will try to
publish a gem for that.
* for the XML format (instead of HTML), the client needs to set BOTH the
Accepts and the Content-Type headers. You could use curl to test. Like this:
...
request << "--header 'Accept:application/xml'"
request << "--header 'Content-Type:application/xml; charset=utf-8'"
HTH.
Call me if you have more questions on this.
Peter