Does anyone know of any good methods for converting records to an XML database?
those. if I have a table named "Users" with the fields "first_name", "age", "last_name", I would like to convert the table to:
<Users> <first_name>Papa</first_name> <age>50</age> <last_name>John</last_name> </Users>
In PostgreSQL, you might like this:
SELECT table_to_xml('users', true, false, '');
Or
SELECT query_to_xml('SELECT * FROM users', true, false, '');
There are other options, just check the manual .
This is a database independent question; it can be executed from any database supported by ActiveRecord .
ActiveRecord
User.find(some_id).to_xml(:except => [:id,:created_at,:updated_at])
:except => [:id,:created_at,:updated_at] removes the default Rails columns from the XML output.
:except => [:id,:created_at,:updated_at]
There is an interesting blog post on this blog: http://ryandaigle.com/articles/2007/4/13/what-s-new-in-edge-rails-a-more-flexible-to_xml