From: ted Date: 2005-09-04T09:31:28+09:00 Subject: Re: How to get REXML to return items in order?? Thanks Gavin. Unfortunately I can't remove the anchors. The html is just a sample of the documents (not my docs) that I'm given to parse. Someone on IRC mentioned that XPath 1.0 doesn't guarantee the order of elements. "Gavin Kistner" wrote in message news:6A73B666-6668-430A-8C58-96DC8294A970@refinery.com... > 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 = < > > table> > >
1st Title
table> > >
2nd Title
table> > > ENDHTML > > require 'rexml/document' > xml = REXML::Document.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] > 3rd Title > 1st Title > 2nd Title >
3rd Title