On Mar 18, 2:00 am, Gary Wright <gwtm... / mac.com> wrote:
> 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

well my sorting criteria something different from that.Consider this;

        <fixedRecordData name="EntityIdentifierStruct">
                <field name="FederateID" dataType="short int"/>
		<field name="FederateIdentifier" dataType="FederateIdentifierStruct"/
>
		<field name="orientation" dataType="OrientationStruct"/>
	</fixedRecordData>
       <fixedRecordData name="FederateIdentifierStruct">
		<field name="SiteID" dataType="short int"/>
		<field name="ApplicationID" dataType="long int"/>
       </fixedRecordData>
  EntityIdentifierStruct depends on FederateIdentifierStruct
  and FederateIdentifierStruct depends on none (primitives not
important)
  and i also have to extract that denpendency information from child
  node attributes so one to one comparison wont work. So I have
  to compose a dependency graph first and keep it somewhere
  (I am thinking the element itself ,so the need for instance
variable) only
  then i can give it to tsort_each_child to iterate over..,
  hurcan