O'Reilly logo

Essential ActionScript 3.0 by Colin Moock

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Determining Equality in E4X

The following sections describe ActionScript's special rules for determining the equality of XML, XMLList, QName, and Namespace objects. Note, however, that the following sections apply to the equality operator (==) only, not to the strict equality (===) operator. E4X does not modify the semantics of the strict equality operator. Specifically, the strict equality operator considers two instances of XML, XMLList, QName (qualified name), or Namespace equal if, and only if, they point to the same object reference.

XML Equality

Two XML instances representing elements are considered equal by the equality operator (==) if the XML hierarchy they represent is identical. For example, in the following code, the variables x1 and x2 point to different object references but are considered equal because they represent the same XML hierarchy.

var x1:XML = <a><b></b></a>;
var x2:XML = <a><b></b></a>;
trace(x1 == x2);  // Displays: true

By default, E4X ignores whitespace nodes, so two XML instances representing elements are considered equal when they have the same markup even if they have different formatting. For example, in the following code the XML source code for the XML instance in x1 contains no whitespace nodes, while the XML source code for the XML instance in x2, contains two whitespace nodes; despite this difference, the instances are still considered equal because the whitespace is ignored, so the XML hierarchies are the same.

var x1:XML = <a><b></b></a>; var x2:XML ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required