Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Loading XML file from web

2 views
Skip to first unread message

Sing...@gmail.com

unread,
Aug 8, 2005, 10:32:38 PM8/8/05
to
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!

Szymon Rozga

unread,
Aug 8, 2005, 11:09:50 PM8/8/05
to
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)

James Britt

unread,
Aug 8, 2005, 11:20:23 PM8/8/05
to

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


Kevin Olbrich

unread,
Aug 8, 2005, 11:33:13 PM8/8/05
to
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

Sing...@gmail.com

unread,
Aug 9, 2005, 3:09:03 AM8/9/05
to
Thank you, yours was the one which worked. The others caused parsing
errors.

Thanks!

0 new messages