From: brabuhr@... Date: 2010-11-21T06:39:39+09:00 Subject: Re: Comparing XML documents On Sat, Nov 20, 2010 at 5:17 AM, Toby Rodwell wrote: > I'd like to check the equivalence of two XML documents.  Searching this > forum I found some short and elegant code, but it considered docs > unequal if their elements were in a different order.  Any > suggestions/advice?  Thanks in advance. require 'active_support' require 'active_support/xml_mini' require 'active_support/core_ext/hash' doc1 = Hash.from_xml < 1 2 END doc2 = Hash.from_xml < 1 2 END # assert_equal doc1, doc2 #=> pass doc3 = Hash.from_xml < 2 1 END # assert_equal doc1, doc3 #=> fail def foo thing case thing when Hash thing.each{|_, t| foo t} when Array thing.sort! thing.each{|t| foo t} end end # assert_equal doc1, foo(doc3) #=> true