From: Jeff Wood Date: 2005-10-18T00:54:56+09:00 Subject: Re: Unit Testing with REXML questions My mistake I meant for the param to be sent to "each" count = 0 xml.elements.each( "/a/d" ) { count += 1 } puts count j. On 10/17/05, Peter Fitzgibbons wrote: > On 10/17/05, umitanuki wrote: > > Hi Jeff, and Peter, > > > > I also got "5" with this code: > > > > xml.elements['/a/d'].size > > > > And then I checked your code like: > > > > xml.elements('/a/d') , > > > > it failed with message > > " in 'elements': wrong number of arguments(1 for 0) (Argument Error) ". > > > > Is it the difference of REXML version?? > > My REXML is 3.1.2.1. > > > > Regards, > > > > > > umitanuki > > > > > > Jeff Wood wrote: > > > Peter, > > > > > > Actually... i don't understand why you got "5" when you did size... > > > that was one element. > > > > > > And yes, an element contains it's children ... but they aren't going > > > to be iterated over unless you did something like /a/d/* or something > > > like that. > > > > > > what do you get when you run > > > > > > count = 0 ; xml.elements( '/a/d' ).each { count += 1 ) ; puts count > > > > > > ... of course umitanuki's to_a should also simply return an array of 1 length. > > > > > > j. > > > > > > On 10/16/05, umitanuki wrote: > > > > > >>Hi Peter, > > >> > > >>What you want is to get the array of specific nodes, isn't it?? > > >>If it's true, see code below: > > >> > > >>xmltest.rb : > > >>require 'rexml/document' > > >> > > >>xmlin = < > >> > > >> one > > >> two > > >> > > >> three > > >> four > > >> > > >> > > >>EOD > > >> > > >>xml = REXML::Document.new(xmlin) > > >>puts xml.elements.to_a('/a/d') > > >> > > >>-- > > >>then, you can iterate with the nodes of 'd', including knowing > > >>the number of 'd' nodes with '.size' method, right?? > > >> > > >>Regards, > > >> > > >> > > >>umitanuki > > >> > > >> > > >>Peter Fitzgibbons wrote: > > >> > > >>>HI Jeff, > > >>> > > >>>xmltest.rb : > > >>>require 'rexml/document' > > >>> > > >>>xmlin = < > >>> > > >>> one > > >>> two > > >>> > > >>> three > > >>> four > > >>> > > >>> > > >>>EOD > > >>> > > >>>xml = REXML::Document.new(xmlin) > > >>>puts xml.elements['/a/d'].size > > >>>puts xml.elements['/a/d'] > > >>> > > >>> > > >>>output : > > >>>5 > > >>> > > >>> three > > >>> four > > >>> > > >>> > > >>>xml.elements['/a/d'] returns the entire xml tree under/including /a/d > > >>> > > >>>I want this to return 1 (the number of "d" elements in the list) > > >>> > > >>> > > >>> > > >> > > >> > > >> > > > > > > > > > -- > > > "http://ruby-lang.org -- do you ruby?" > > > > > > Jeff Wood > > > > > > > > > > > > > > > > > > > My code was : > > puts xml.elements['/a/d'].size > > in previous post. > > -- "http://ruby-lang.org -- do you ruby?" Jeff Wood