Topic: How to fetch a XML file from another website using Ruby On Rails?

I am trying to find the way to fetch a XML file from another website using Ruby On Rails. One possible way that I could thought is to use website crawl method e.g. SimpleCrawler library.
I have searched this topic over Internet, and still didn't have clue.  I am wondering is there any other more elegant way to directly fetch the XML file and parse it?
thanks in advance.

Last edited by supposethis (2011-07-11 17:21:37)

Re: How to fetch a XML file from another website using Ruby On Rails?

supposethis wrote:

I am trying to find the way to fetch a XML file from another website using Ruby On Rails. One possible way that I could thought is to use website crawl method e.g. SimpleCrawler library.
I have searched this topic over Internet, and still didn't have clue.  I am wondering is there any other more elegant way to directly fetch the XML file and parse it?
thanks in advance.

If you're getting the xml in order to build an object then you should look at ActiveResource, which is Rails' built in system for dealing with external data (ie data from other sites).

XmlSimple is a good xml parser http://xml-simple.rubyforge.org/

Making your own get or post requests to external sites from inside your code is simple: http://travisonrails.com/2007/11/07/htt … -with-ruby

###########################################
#If i've helped you then please recommend me at Working With Rails:
#http://www.workingwithrails.com/person/ … i-williams

Re: How to fetch a XML file from another website using Ruby On Rails?

This is very helpful answer. Thanks Max for your time to read and type these words.

Get the job done. Although I still cannot get xmlsimple work on Ubuntu server10.04. It always report "cannot load xmlsimple" but this library did installed use gem.

just fetch the XML file from remote server and store it to the public directory of local ROR server. then I use jQuery JavaScript to load xml file and parse it from another static html file

Last edited by supposethis (2011-07-15 17:24:42)

Re: How to fetch a XML file from another website using Ruby On Rails?

I've used the REXML library to parse XML files.  We're running on Ubuntu and there's no issue. Works pretty well although I've heard some folks complain about performance.

Play postseason fantasy sports at Fantasy Postseason - Written in RoR

Re: How to fetch a XML file from another website using Ruby On Rails?

All XML parsing should be done with Nokogiri. REXML is dog-slow.

As for using ActiveResource. I found that to be pretty useless unless you are interacting with an app which uses rail's RESTful style.

I would just use the HTTP library of your choice to grab the URL, parse it with Nokogiri and away you go.