It looks like REXML already provides the two
iterators you need to satisfy TSort.  Try this:

require 'rexml/document'
require 'tsort'

class REXML::Element
   include TSort
   def tsort_each_node(&block)
     each_recursive(&block)
   end
   def tsort_each_child(node, &block)
     node.each_child(&block) if node.respond_to?(:each_child)
   end
end

doc = REXML::Document.new <<EOS
<mydoc>
   <someelement attribute="nanoo">Text, text, text</someelement>
</mydoc>
EOS
p doc.tsort



Gary Wright