Loading XML file from web

I am looking to open an xml file from the web.

The xml file is located at http://www.digg.com/rss/index.xml

I want it to work something like this...

require "rexml/document"
include REXML
file = File.new( "http://www.digg.com/rss/index.xml" )
doc = Document.new file

BUT!
This line doesn't work: file = File.new(
"http://www.digg.com/rss/index.xml" )

How do i load an xml file from the web?
Thanks!

This is pretty much straight from the documentation of Net::HTTP

require 'net/http'
Net::HTTP.start('www.digg.com', 80) { |http|
  response = http.get('rss/index.xml')
  response.body # this is the text of www.digg.com/rss/index.xml
}

so simply now create an instance of Document with the text
response.body (I haven't tried this out myself, but should work)

Szymon Rozga wrote:

This is pretty much straight from the documentation of Net::HTTP

require 'net/http'
Net::HTTP.start('www.digg.com', 80) { |http|
  response = http.get('rss/index.xml')
  response.body # this is the text of Digg Top Stories
}

so simply now create an instance of Document with the text
response.body (I haven't tried this out myself, but should work)

Or use open-uri.

http://www.ruby-doc.org/stdlib/libdoc/open-uri/rdoc/

James

···

--

http://www.ruby-doc.org - The Ruby Documentation Site
http://www.rubyxml.com - News, Articles, and Listings for Ruby & XML
http://www.rubystuff.com - The Ruby Store for Ruby Stuff
http://www.jamesbritt.com - Playing with Better Toys

How about this....

···

--
require "open-uri"
open("http://www.digg.com/rss/index.xml") do |file|
  file.each_line {|line| puts line}
end
--

This will just dump the contents of the file.
-Kevin

-----Original Message-----
From: Szymon Rozga [mailto:szymon.rozga@gmail.com]
Sent: Monday, August 08, 2005 11:11 PM
To: ruby-talk ML
Subject: Re: Loading XML file from web

This is pretty much straight from the documentation of Net::HTTP

require 'net/http'
Net::HTTP.start('www.digg.com', 80) { |http|
  response = http.get('rss/index.xml')
  response.body # this is the text of www.digg.com/rss/index.xml }

so simply now create an instance of Document with the text response.body (I
haven't tried this out myself, but should work)

Thank you, yours was the one which worked. The others caused parsing
errors.

Thanks!