Instead of spending hours trying to write something custom to convert your hash into xml or vice versa, you can do it in one line. If you are already in a Rails environment, you are good to go, but if using ruby, include the ActiveSupport gem:
require 'rubygems' require 'active_support'
Now that you have, we can convert a xml to a hash:
hash = Hash.from_xml(xml_stream)
And a hash to xml is stupid simple:
xml = hash.to_xmlThere you have it, simple xml to hash and hash to xml!

October 21st, 2008 at 12:20 pm
If you ‘re interested in this, also look at: http://rubyforge.org/projects/hashtoxml/