The Artima Developer Community
Sponsored Link

Java Buzz Forum
Hpricot is great

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
dion

Posts: 5028
Nickname: dion
Registered: Feb, 2003

Dion Almaer is the Editor-in-Chief for TheServerSide.com, and is an enterprise Java evangelist
Hpricot is great Posted: Mar 13, 2007 11:12 AM
Reply to this message Reply

This post originated from an RSS feed registered with Java Buzz by dion.
Original Post: Hpricot is great
Feed Title: techno.blog(Dion)
Feed URL: http://feeds.feedburner.com/dion
Feed Description: blogging about life the universe and everything tech
Latest Java Buzz Posts
Latest Java Buzz Posts by dion
Latest Posts From techno.blog(Dion)

Advertisement

I used to cringe at having to work with XML. These days there are nice ways to work with it... from E4X to Groovy builders, and of course with Hpricot.

I wanted to take my OPML file and grep out the URLs so I could create a custom search engine that would search over my buddies (from the OPML file).

It is basically a one-liner with Hpricot:

require 'rubygems'
require 'hpricot'

filename = ARGV.first || 'mysubscriptions.opml'

doc = open(filename) { |f| Hpricot(f) }

(doc/"outline[@htmlurl]").each do |url|
puts url.attributes['htmlurl']
end

In my case the OPML file is just sitting on disk there, but I could easily have it grab the file from a URL:

require 'open-uri'
doc = Hpricot(open("http://almaer.com/mysubs.opml"))

Not bad until we implement JsDOM ;)

Read: Hpricot is great

Topic: Software and Computer Systems Company, LLC has released FastPak for Java 1.2.10.55, a $30... Previous Topic   Next Topic Topic: Guicy Spring

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use