Gavin Kistner wrote:
> On Sep 3, 2005, at 3:16 PM, ted wrote:
> > I'm new to Ruby and can't figure out why REXML isn't returning the
> > elements
> > in the order they appear in the document. Here's my code and the
> > document.
>
> I confirm the problem. Looks like a bug. [...]


.... and it's fixed in CVS for 1.8.3

If you need this now, you could download the later version here:
http://www.ruby-lang.org/cgi-bin/cvsweb.cgi/ruby/lib/rexml/rexml.tar.gz?only_with_tag=ruby_1_8;tarball=1

to e.g. "C:\Ruby\TEMP" then change the lookup path at the top of your script.



$:.unshift('C:/Ruby/TEMP')  #  for rexml fixes
require 'rexml/document'
xml = REXML::Document.new(DATA)
xml.elements.each("//span[@class='c5']") do |element|
  puts element
end

#-> <span class='c5'><b>1st Title</b></span>
#-> <span class='c5'><b>2nd Title</b></span>
#-> <span class='c5'><b>3rd Title</b></span>

__END__
<html>
<body>
<a name="1"/>
<table><tr><td><span class="c5"><b>1st Title</b></span></td></tr></table>
<a name="2"/>
<table><tr><td><span class="c5"><b>2nd Title</b></span></td></tr></table>
<a name="3"/>
<table><tr><td><span class="c5"><b>3rd Title</b></span></td></tr>
</table>
</body>
</html>


daz