title: How to use Nokogiri's xpath and at_xpath methods
body: <p>I'm learning how to use Nokogiri and few questions came to me based on this code:</p>
  
  <pre><code>require 'rubygems'
  require 'mechanize'
  
  post_agent = WWW::Mechanize.new
  post_page = post_agent.get('http://www.vbulletin.org/forum/showthread.php?t=230708')
  
  puts "\nabsolute path with tbody gives nil"
  puts  post_page.parser.xpath('/html/body/div/div/div/div/div/table/tbody/tr/td/div[2]').xpath('text()').to_s.strip.inspect
  
  puts "\n.at_xpath gives an empty string"
  puts post_page.parser.at_xpath("//div[@id='posts']/div/table/tr/td/div[2]").at_xpath('text()').to_s.strip.inspect
  
  puts "\ntwo lines solution with .at_xpath gives an empty string"
  rows =   post_page.parser.xpath("//div[@id='posts']/div/table/tr/td/div[2]")
  puts rows[0].at_xpath('text()').to_s.strip.inspect
  
  
  puts
  puts "two lines working code"
  rows =   post_page.parser.xpath("//div[@id='posts']/div/table/tr/td/div[2]")
  puts rows[0].xpath('text()').to_s.strip
  
  puts "\none line working code"
  puts post_page.parser.xpath("//div[@id='posts']/div/table/tr/td/div[2]")[0].xpath('text()').to_s.strip
  
  puts "\nanother one line code"
  puts post_page.parser.at_xpath("//div[@id='posts']/div/table/tr/td/div[2]").xpath('text()').to_s.strip
  
  puts "\none line code with full path"
  puts post_page.parser.xpath("/html/body/div/div/div/div/div/table/tr/td/div[2]")[0].xpath('text()').to_s.strip
  </code></pre>
  
  <ul>
  <li>Is it better to use <code>//</code> or <code>/</code> in XPath? <a href="https://stackoverflow.com/questions/1982624/using-xpath-how-do-i-select-a-node-based-on-its-text-content-and-value-of-an-att/1982666#1982666">@AnthonyWJones</a> says that "the use of an unprefixed <code>//</code>" is not such a good idea.</li>
  <li>I had to remove <code>tbody</code> from any working XPath otherwise I got a <code>nil</code> result. How is possible to remove an element from the XPath to get things to work?</li>
  <li>Do I have to use <code>xpath</code> twice to extract data if not using a full XPath?</li>
  <li>Why can't I make <code>at_xpath</code> work to extract data? It works nicely in "<a href="https://stackoverflow.com/questions/2062051/ruby-nokogiri-parsing-html-table-ii/2062210#2062210">How do I parse an HTML table with Nokogiri?</a>". What is the difference?</li>
  </ul>