April 23, 2014
Hot Topics:
RSS RSS feed Download our iPhone app

Parsing XML with Hpricot, a Gem of a Ruby Gem

  • January 5, 2010
  • By Jason Gilmore
  • Send Email »
  • More Articles »

XML is often touted as being "human readable." In fact, the goal was to avoid having to spend too much time trying to parse the language at all. However, XML often falls short of that goal. Luckily for Ruby developers, a quick search for a parsing solution will turn up Hpricot. This Ruby gem can parse and manipulate XML with amazing flexibility and ease.

In his Web Developer's Virtual Library (WDVL) tutorial, Jason Gilmore introduces Hpricot, showing you how to begin using this powerful gem in ways that will leave you with plenty of time to read something far more exciting than XML.

Installing the Hpricot Gem

Hpricot is packaged as a Ruby gem, meaning the easiest way to install it is to use the RubyGems package manager. Of course, this also means you'll need to install Ruby, so take care of that now if Ruby's not already installed on your system.

Next, install Hpricot by opening a terminal window and executing the following command:

%>gem install hpricot

You can confirm Hpricot installed correctly by firing up the interactive ruby shell, better known as the irb, and using the require method to load the Hpricot library:

%>irb
irb(main):001:0> require 'hpricot'
=>true
irb(main):002:0>

With Hpricot installed, you're ready to begin parsing XML! Read the entire tutorial on parsing XML with Hpricot on WDVL.


Tags: open source, Ruby, XML, XML Parser




Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 


Sitemap | Contact Us

Rocket Fuel