On Mon, Jan 12, 2009 at 04:54:26AM +0900, matt mitchell wrote:
> On Jan 9, 6:01m, Aaron Patterson <aa... / tenderlovemaking.com> wrote:
> > Hi Matt,
> >
> > On Sat, Jan 10, 2009 at 04:16:22AM +0900, goodieboy wrote:
> > > OK, was completely sold on Hpricot and now am having my doubts. I
> > > can't seem to get to any of the docs (the site is down). Is it still
> > > being developed? Who are the developers? I love the API and really am
> > > hoping to use it...
> >
> > > So then I tried out Nokogiri and it works well. The bug that Hpricot
> > > had (re-naming a node only names the open-tag) is not present in
> > > Nokogiri. Great! But it's built on libxml, which I don't know much
> > > about. It seems a little more heavy weight than Hpricot. I also heard
> > > that the main developer for libxml doesn't have much time to devote to
> > > the project.
> >
> > Yes, Nokogiri is built on top of the libxml2 project from Gnome.
> > libxml2 is actively developed and well supported since it is the XML
> > parser used by the Gnome project:
> >
> > ttp://xmlsoft.org/
> >
> > If you find bugs, we have a
> >
> > * mailing list:http://rubyforge.org/mailman/listinfo/nokogiri-talk
> > * IRC Channel on freenode: #nokogiri
> > * Ticketing system:
> > ttp://nokogiri.lighthouseapp.com/projects/19607-nokogiri/overview
> > * RDoc:http://nokogiri.rubyforge.org/nokogiri/
> >
> > I've switched my projects from Hpricot to Nokogiri, and I'm quite happy.
> >
> > --
> > Aaron Pattersonhttp://tenderlovemaking.com/
> 
> This is great thank you. Definitely helps clear things up a bit. So
> it's not just me... Hpricot has a few bugs that have been around for a
> while. That's too bad :(
> 
> OK, for a quick Nokogiri question... is it possible to ask a node if
> it responds to a certain xpath? Something like:
> 
> matching = nodes.select{|n| n.is_findable_by('[@class=plant]') }

I can't think of a good xpathy way to do that from the current node.
You could do something like this:

  matching = nodes.select { |n|
    n.parent.xpath('./*[@class="plant"]').include?(n)
  }

That might get kind of slow though.  If you know that "class" is the
attribute you're looking for, you could just do something like this:

  matching = nodes.select { |n| n['class'] == "plant" }

Hope that helps.

-- 
Aaron Patterson
http://tenderlovemaking.com/