I'm a bit of a newbie to Ruby, and to xpath..... and hoping someone 
here can give me the one-liner version of why this is failing.


I have an XML structure like:

<foos>
	<foo>
	<fooID>Foo1</fooID>
	<subfoos>
		<subfoo>
			<subfooName>foobar1</subfooName>
		</subfoo>
		<subfoo>
			<subfooName>foobar2</subfooName>
		</subfoo>
	</subfoos>
	</foo>
	<foo>
	<fooID>Foo2</fooID>
	<subfoos>
		<subfoo>
			<subfooName>foobar3</subfooName>
		</subfoo>
		<subfoo>
			<subfooName>foobar4</subfooName>
		</subfoo>
	</subfoos>
	</foo>
</foos>

And the code

doc.each_element('//foo') { |foo|
  puts "*** Processing #{foo.elements['fooId'].text}"
  foo.each_element('//subFoo') { |subFoo|
    puts subFoo.elements["subfooName"].text
    }
  }


What I was expecting was a nested loop.. but what I get is:

doc.each_element('//foo') { |foo|

This iterator does what I expect.

  foo.each_element('//subFoo') { |subFoo|

This iterator seems to give me all instances of subFoo in doc, not just 
in the current instance of foo.


I'm sure this i just something about ruby that I don't understand... 
but can someone point me in the right direction?


Cheers

ash