Forum: Ruby xml/libxml "first" method doesn't work

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Ingo W. (Guest)
on 2006-05-06 23:40
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
Ross B. (Guest)
on 2006-05-07 20:03
(Received via mailing list)
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"> [...]
This topic is locked and can not be replied to.