This is likely to be rather slow, but if you really need to do a recursive 
comparison of XML objects, it's probably reasonable. I don't know of any 
built-in operator or method that does deep equality.

Gordon Smith
Adobe Flex SDK Team

From: flexcoders@yahoogroups.com [mailto:flexcod...@yahoogroups.com] On Behalf 
Of Davis Ford
Sent: Wednesday, January 06, 2010 5:22 PM
To: flexcoders@yahoogroups.com
Subject: Re: [flexcoders] Testing for XML equality



I found a solution:

import mx.utils.ObjectUtil;

Assert.assertTrue(ObjectUtil.compare(xml1, xml2) == 0);

That does the trick.

Regards,
Davis
On Wed, Jan 6, 2010 at 8:20 PM, Paul Andrews 
<p...@ipauland.com<mailto:p...@ipauland.com>> wrote:
Davis Ford wrote:
>
>
> Hi Paul,
>
> I don't believe this is correct for ActionScript3.  Strict equality is
> the "===" operator which compares object instances.  "==" should test
> for equality.
I tried (in Flash)..

var objA:Object = {a:1};
var objB:Object = {a:1};
trace(objA==objB);  // false
var xmlA:XML = <x>xxx</x>;
var xmlB:XML = <x>xxx</x>;
trace(xmlA==xmlB);  // true
trace(xmlA===xmlB);  // false

and indeed you are right. I didn't know that XML was treated differently
from vanilla object in comparisons.

Thanks.

Paul
>
> If you change the test to this...
>
> [Test]
>         public function testXmlEquality():void {
>          var xml1:XML =
>          <a>
>          <b></b>
>          <c></c>
>          </a>;
>          var xml2:XML =
>          <a>
>          <b></b>
>          <c></c>
>          </a>;
>          xml1.normalize();
>          xml2.normalize();
>          Assert.assertTrue(xml1 == xml2);
>         }
>
> it passes.  XML/e4x is supposed to support this out of the box, and it
> does -- to a degree.  Although, semantically and syntactically, xml1
> and xml2 from the 1st test are equivalent, e4x is not thinking so, and
> I think that is broken.  Searching for a workaround has popped up very
> little, which is why I was hoping someone on the list might have a
> good answer for why this is, and how I can test XML equivalence
> without caring about element ordering.
>
> Regards,
> Davis
>
> On Wed, Jan 6, 2010 at 7:03 PM, Paul Andrews 
> <p...@ipauland.com<mailto:p...@ipauland.com>
> <mailto:p...@ipauland.com<mailto:p...@ipauland.com>>> wrote:
>
>
>     Davis Ford wrote:
>     >
>     >
>     > Why does this test fail? Is there any way to test for equality that
>     > ignores the ordering of elements -- which shouldn't technically
>     matter?
>     >
>     > [Test]
>     > public function testXmlEquality():void {
>     > var xml1:XML =
>     > <a>
>     > <b></b>
>     > <c></c>
>     > </a>;
>     > var xml2:XML =
>     > <a>
>     > <c></c>
>     > <b></b>
>     > </a>;
>     > Assert.assertTrue(xml1 == xml2);
>     > }
>     xml1 and xml2 are references to objects. Because they are different
>     objects they are not equal - the references are different.
>     >
>     >
>     >
>     >
>     >
>
>
>
>
> --
> Zeno Consulting, Inc.
> home: http://www.zenoconsulting.biz
> blog: http://zenoconsulting.wikidot.com
> p: 248.894.4922
> f: 313.884.2977
>
>
>


------------------------------------

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Alternative FAQ location: 
https://share.acrobat.com/adc/document.do?docid=942dbdc8-e469-446f-b4cf-1e62079f6847
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.comYahoo! 
Groups Links

   Individual Email | Traditional





--
Zeno Consulting, Inc.
home: http://www.zenoconsulting.biz
blog: http://zenoconsulting.wikidot.com
p: 248.894.4922
f: 313.884.2977

Reply via email to