From: ruby talk Date: 2006-12-16T03:55:15+09:00 Subject: Re: Hpricot html parsing Ask: http://code.whytheluckystiff.net/hpricot/ticket/32 text in xpath should return a text node if present. For example: (doc/"/html/body/div[1]/*/table[0]/tr[0]/*/b[9]/text") Currently I am using the search and next_node: doc.search("/html/body/div[1]/*/table[0]/tr[0]/td/b"){|x| @movie_plot=x.next_node.to_s.strip if x.inner_html=="Plot Outline:" } And receive Author: why Message: * lib/hpricot/elements.rb: added support for selecting text nodes with text(): //p/text(), //p[a]//text(), etc. * lib/hpricot/traverse.rb: ditto. * lib/hpricot/tag.rb: the pathname method reports the path fragment needed to get to this node. * lib/hpricot/parse.rb: handle possible empty processing instruction. http://code.whytheluckystiff.net/hpricot/changeset/87 On 12/13/06, David Vallner wrote: > Peter Szinek wrote: > > paragraphs = doc/'p' > > > > good_elems = paragraphs.map.reject {|elem| ((elem/"img").empty?) } > > Which once again makes me wish paragraphs = doc/'//p[img]/text()' > worked. This could be doable if you asked Hpricot to provide you with > the REXML document (it's probably out of scope for the intendedly simple > XPath engine Hpricot uses natively), but unfortunately I can't for the > heck of it figure out how to make REXML accept the final /text(), even > though the parser claims to support XPath 1.0 except a few exceptions, > that one not being noted. > > David Vallner > > > >