--Apple-Mail-2--692775499
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
delsp=yes;
format=flowed
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. If I remove some of the
anchors, it works.
(Off-topic - no need to use empty named anchors in your page - just
use IDs on existing elements instead.)
Sliver:~/Desktop] gkistner$ cat tmp.rb
code = <<ENDHTML
<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>
ENDHTML
require 'rexml/document'
xml = REXML:

ocument.new( code );
xml.elements.each( "//span[@class='c5']" ) do |element|
puts element
end
[Sliver:~/Desktop] gkistner$ ruby -v tmp.rb
ruby 1.8.2 (2004-12-25) [powerpc-darwin7.7.2]
<span class='c5'><b>3rd Title</b></span>
<span class='c5'><b>1st Title</b></span>
<span class='c5'><b>2nd Title</b></span>
--Apple-Mail-2--692775499--