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
Thank you, yours was the one which worked. The others caused parsing
errors.
Thanks!