http://www.ruby-doc.org/stdlib-1.9.3/libdoc/rexml/... includes the following example: doc = Document.new '<a><b/><c/><d/>sean<b/><c/><d/></a>' doc.root.each {|e|p e} #-> Yields b, c, d, b, c, d elements doc.root.each('b') {|e|p e} #-> Yields b, b elements However when I run it I get the results below. Am I doing something wrong? If not, is the documentation or the code correct? Should I be reporting this somewhere? (My underlying goal is to find an iterator that yields one element at a time from an XPath search, rather than doing the whole search to return a complete array of elements.) Running the example: Sleek:iTunes_Library_Update Wes$ rvm 1.9.3 Sleek:iTunes_Library_Update Wes$ ruby -v ruby 1.9.3p327 (2012-11-10) [x86_64-darwin12.2.0] Sleek:iTunes_Library_Update Wes$ ruby rexml_question.rb <b/> <c/> <d/> "sean" <b/> <c/> <d/> /Users/Wes/.rvm/rubies/ruby-1.9.3-p327/lib/ruby/1.9.1/rexml/parent.rb:40:in `each': wrong number of arguments (1 for 0) (ArgumentError) from rexml_question.rb:10:in `<main>' Sleek:iTunes_Library_Update Wes$ cat < rexml_question.rb #! /usr/bin/env ruby require "rexml/document" include REXML STDOUT.sync = true doc = Document.new '<a><b/><c/><d/>sean<b/><c/><d/></a>' doc.root.each {|e|p e} #-> Yields b, c, d, b, c, d elements doc.root.each('b') {|e|p e} #-> Yields b, b elements doc.root.each('child::node()') {|e|p e} #-> Yields <b/>, <c/>, <d/>, <b/>, <c/>, <d/> XPath.each(doc.root, 'child::node()', &block) #-> Yields <b/>, <c/>, <d/>, sean, <b/>, <c/>, <d/> Sleek:iTunes_Library_Update Wes$
on 2013-01-03 06:26
on 2013-01-03 09:46
Hi, In <6d6542a4ef59a1f0c4bb61d35bff3909@ruby-forum.com> "rexml.elements.each vs 1.9.3 documentation for same" on Thu, 3 Jan 2013 14:26:56 +0900, Wesley Rishel <lists@ruby-forum.com> wrote: > Am I doing something wrong? If not, is the documentation or the code > correct? Should I be reporting this somewhere? Thanks for your report. The sample code in the documentation is wrong. It should be doc.root.elements.each instead of doc.root.each . I've fixed it in trunk. Thanks,
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.