Recent comments


Syndicate


Follow Me

Twitter Facebook

Ruby's Hpricot

As the next step to my Ruby adventure, I figured I'll create some Ruby libraries which I don't care if someone already implemented a similar one. I just want to practice mashing things up on Ruby.

My first candidate is creating a Twitter library and for that I know I need some xml parsing. Like in any high-level programming language, Ruby has a built-in parser. Its fast but not as elegant so I went looking and found Hpricot, It has very elegent style and its so simple.

So to test things out, I download an rss feed from this blog and tried parsing it using my newly disscovered gem.

require 'rubygems'
require 'hpricot'

doc = Hpricot.XML(open("rss.xml"))

(doc/:item).each do |item|
  puts (item/:title).inner_html
  puts (item/:link).inner_html
  puts ''
end

and the output:

Hello Ramaze
http://marconijr.com/content/hello-ramaze

Ruby Mixins
http://marconijr.com/content/ruby-mixins

Automatic Zen Subtheme
http://marconijr.com/content/automatic-zen-subtheme

ORM
http://marconijr.com/content/orm

Now I'm ready for my next iteration on twitter.