# Strange xpath output

**URL:** <https://www.ruby-forum.com/t/strange-xpath-output/191086>\
**Category:** Ruby\
**Created:** [July 5, 2010, 4:00am UTC](https://www.ruby-forum.com/t/strange-xpath-output/191086 "2010-07-05T04:00:36Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [July 5, 2010, 4:00am UTC](https://www.ruby-forum.com/t/strange-xpath-output/191086/1 "2010-07-05T04:00:36Z")

</div>

/home/pt/jiexi content is:

- 
- 
- 
- 

require ‘rubygems’  
require ‘nokogiri’  
doc = Nokogiri::HTML.parse(open(’/home/pt/jiexi’))  
table=doc.xpath(’//ul[@id=“ul\_list”]/li/a’)  
puts table  
output  
irb(main):005:0\> puts table  
  
  
  
  
=\> nil  
puts table.xpath(’//ul’)  
irb(main):006:0\> puts table.xpath(’//ul’)

- 
- 
- 
- 

what i think is the script “puts table.xpath(’//ul’)” will not create  
any output.  
how strange it is to get the result,would you mind to tell me why?

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [July 5, 2010, 6:36am UTC](https://www.ruby-forum.com/t/strange-xpath-output/191086/2 "2010-07-05T06:36:39Z")

</div>

On Mon, Jul 05, 2010 at 11:00:38AM +0900, Pen T. wrote:

> title="ok3"\>- 
> 
> what i think is the script “puts table.xpath(’//ul’)” will not create  
> any output.  
> how strange it is to get the result,would you mind to tell me why?

“//ul” says “find all ul tags anywhere in the document”. It looks like  
you have a ul tag in your document, and the XPath is doing what it is  
supposed to do.

Why would you expect “//ul” to have no results?

---

<div class="post-metadata">

**Author:** ![luofeiyu](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/9de0a6/32.png) [@luofeiyu](https://www.ruby-forum.com/u/luofeiyu)\
**Post date:** [July 5, 2010, 7:42am UTC](https://www.ruby-forum.com/t/strange-xpath-output/191086/3 "2010-07-05T07:42:47Z")

</div>

On 05.07.2010 04:00, Pen T. wrote:

> title="ok3"\>- 
> 
> what i think is the script “puts table.xpath(‘//ul’)” will not create  
> any output.  
> how strange it is to get the result,would you mind to tell me why?

That’s perfectly expected. If you look closely at the eplanation,  
you’ll find out:

[http://www.w3schools.com/Xpath/xpath\_syntax.asp](http://www.w3schools.com/Xpath/xpath_syntax.asp)

You probably wanted

puts table.xpath(‘ul’)

Kind regards

robert
