# Xml/libxml "first" method doesn't work

**URL:** <https://www.ruby-forum.com/t/xml-libxml-first-method-doesnt-work/59801>\
**Category:** Ruby\
**Created:** [May 6, 2006, 9:40pm UTC](https://www.ruby-forum.com/t/xml-libxml-first-method-doesnt-work/59801 "2006-05-06T21:40:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [May 6, 2006, 9:40pm UTC](https://www.ruby-forum.com/t/xml-libxml-first-method-doesnt-work/59801/1 "2006-05-06T21:40:50Z")

</div>

Hello,

I am having a problem with the xml/libxml Ruby Gem

doc = XML::Document.file(‘myfile.xml’)  
mynodes = doc.find(’[xpath statement here]’)  
mynodes.length  
=\> 20  
mynodes.first  
=\> NoMethodError: undefined method `first’ for  
#XML::Node::Set:0x31039c

The Doc does mention a “first” method for XML::Node::Set. Is this a bug?

Thanks!  
Ingo

---

<div class="post-metadata">

**Author:** ![ingoweiss](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/i/77aa72/32.png) [@ingoweiss](https://www.ruby-forum.com/u/ingoweiss)\
**Post date:** [May 7, 2006, 6:03pm UTC](https://www.ruby-forum.com/t/xml-libxml-first-method-doesnt-work/59801/2 "2006-05-07T18:03:13Z")

</div>

On Sun, 2006-05-07 at 04:40 +0900, Ingo W. wrote:

> #XML::Node::Set:0x31039c
> 
> The Doc does mention a “first” method for XML::Node::Set. Is this a bug?

This method was introduced in the recent 0.3.8 release, so you may need  
to upgrade from an older version.

require ‘xml/libxml’  
XML::Parser::VERSION

# =\> “0.3.8”

doc = XML::Document.file(‘safs/testlog.xml’)  
set = doc.find(’//log\_message’)

# =\> \<log\_message type=“start testcase”\> […]

set.length

# =\> 3

set.first

# =\> \<log\_message type=“start testcase”\> […]
