LanguagesRuby / RailsParsing XML with Hpricot, a Gem of a Ruby Gem

Parsing XML with Hpricot, a Gem of a Ruby Gem content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More.

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(main):001:0> require 'hpricot'

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

Get the Free Newsletter!

Subscribe to Developer Insider for top news, trends & analysis

Latest Posts

Related Stories