From: Robert Klemme Date: 2010-09-07T17:12:49+09:00 Subject: Re: how to write this xpath? On Tue, Sep 7, 2010 at 9:37 AM, Robert Klemme wrote: > On Tue, Sep 7, 2010 at 9:05 AM, Pen Ttt wrote: >> think for your help,but your method can't work ,i have made a try. > > Ah, I see - it's more complicated.  I think it should be one of these > depending on whether you want the text nodes: > > /html/body/table[1]/tr[1]/td[1]/(.|strong|a) > /html/body/table[1]/tr[1]/td[1]/(.|strong|a)/text() > > but I cannot test it right now since I don't have Nokogiri on this machine. Now this looks awful but apparently it works: $doc.xpath '/html/body/table[1]/tr[1]/td[1]/text()|/html/body/table[1]/tr[1]/td[1]/strong/text()|/html/body/table[1]/tr[1]/td[1]/a/text()' If you want the elements you need to remove all "/text()" from the above. The difficult thing here is that you want to select only a portion of the child nodes of /table/tr/td. Kind regards robert -- remember.guy do |as, often| as.you_can - without end http://blog.rubybestpractices.com/