From: Phlip Date: 2008-08-13T03:47:37+09:00 Subject: Re: Hpricot and xpath Li Chen wrote: > I want to find the path to a tag I am interested using hpricot. > According to the document and examples I think I should use #xpath > method. > > I expect that ruby will return the path as this: > "/tag1/tag2/div[@id='header']" > > but I get the following info: > > tag1.rb:4: undefined method `xpath' for nil:NilClass (NoMethodError) > > I wonder why method #xpath is not defined? You gotta learn what those errors look like. If you have a 'nil' where you don't expect it, the error happens when you use the nil incorrectly, such as calling a method - like xpath - that nil does not have. Your doc.at("header") returns nil. > require 'hpricot' > doc=Hpricot(open('tag.txt')) > puts doc > puts doc.at("header").xpath() What does p doc.at('header') say? Would a .search (or equivalent) for '.header' work? -- Phlip http://www.oreillynet.com/onlamp/blog/2007/08/xpath_checker_and_assert_xpath.html