2

I need to access xml that is located in another web server. Does rails/ruby have a function that allows me to access this xml and then may be store it in a variable so that i can process it with libxml-ruby?

2 Answers 2

3

If you're not making DOM modifications (that is, you don't need the XML structure but rather the data in it) you can use HTTParty, which does all the parsing for you.

For example:

timeline = HTTParty.get("http://twitter.com/statuses/public_timeline.xml", :format => :xml)
timeline["statuses"].map{|status| status["user"]["screen_name"] } # => ["bobby", "johnny", "denisss"]
Sign up to request clarification or add additional context in comments.

Comments

1

There are a number of Ruby-level libraries to access remote HTTP resources. The oldest is Net::HTTP

Once you've received the xml, use Hpricot or other options to parse it.

Added:

Remember that you probably don't want to make your clients wait while your Rails server queries another server. Cache your XML results if you can, or fetch the XML in the background.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.