An external web service is sending json or xml towards my app. What would be the best way to consume this data? Is there a built-in library in Rails or Ruby to do this or do I need to use a gem for this?
+2
A:
For parsing json, you can use rails' method ActiveSupport::JSON.decode directly in your controller code. For what concerns XML parsing instead, you can choose between rexml (included in the ruby Standard Library), hapricot and libxml-ruby (available via ruby gem).
The choice is ultimately a matter of taste and performance. This benchmark claims that libxml-ruby is the fastest one, though it requires a few other libraries.
And
2009-08-08 14:49:34
another nice lib for xml is nokogiri, also a rubygem
Peer Allan
2009-08-08 15:14:26
+1
A:
if it is a web service you query as a source of data, consider making an ActiveResource here is a railscast of the basics
ErsatzRyan
2009-08-08 16:26:38
+1
A:
Try nokogiri.
There's a good explanation of how to use it here:
http://www.robertsosinski.com/2008/12/08/scraping-pages-made-easy-with-ruby-and-nokogiri/
flo
2009-08-10 17:26:38