From: Chris White Date: 2011-07-30T05:57:15+09:00 Subject: Re: encoding problem ---------------------------------------- > Date: Sat, 30 Jul 2011 02:49:58 +0900 > From: trylobeet@gmail.com > Subject: encoding problem > To: ruby-talk@ruby-lang.org > > i'm new to ruby, and having got the basics by now i decided to try and > write a program that fetches RSS feeds and mashes them up into a > burroughs-style cut-up. Here's an alternative that uses a simple xml parsing gem (xml-object), and the standard net/http library: require 'net/http' require 'xml-object' def fetch(uri_str, limit = 10)     # You should choose better exception.     raise ArgumentError, 'HTTP redirect too deep' if limit == 0     response = Net::HTTP.get_response(URI.parse(uri_str))     case response     when Net::HTTPSuccess     then response     when Net::HTTPRedirection then fetch(response['location'], limit - 1)     else         response.error!     end end xml_data = fetch("http://www.slashdot.org/index.rss").body rss = XMLObject.new(xml_data) puts rss.channel.title puts rss.channel.link puts rss.channel.description rss.items.each do |item|     puts item.title     puts item.link     puts item.description end The `fetch()` method is required because this URL redirects multiple times, which by the way the correct URL is: http://rss.slashdot.org/Slashdot/slashdot xml-object lets you access xml as an object. More details on the homepage[1]. You might be able to get faster parsing by using libxml-ruby. This blog has a quick breakdown on performance[2]. I decided to go with xml-object simply because it matched more closely to how you were accessing it. Hope that gives you something to work with. Regards, Chris White Twitter: @cwgem [1] http://xml-object.rubyforge.org/doc/ [2] http://railstips.org/blog/archives/2008/08/11/parsing-xml-with-ruby/