New Classes in Actionscript 3.0 Because E4X is not simply an upgrade of the previous XML functionality, the class structure is not exactly the same. ActionScript 3.0 has the following top-level classes for working with E4X functionality: XML, XMLList, QName, and Namespace. XML The new XML class is nothing like the XML class in ActionScript 2.0. ActionScript 2.0 had two classes that represented the XML structure: XML and XMLNode. The XMLNode class was always a little silly because technically each node is a self-contained XML document. Therefore, in ActionScript 3.0, Adobe corrected this confusion by removing the XMLNode class. Now the XML type represents all elements, attributes, processing instructions, and text. XMLList ActionScript 3.0 introduces a new class called XMLList. In ActionScript 2.0, you could get an array of XMLNode objects by calling the childNodes property of any XMLNode object. Now, instead of working with a generic Array, you can use the XML.children() method to return an XMLList with the same functionality. A nice feature of the XMLList class is that if you have a case where there is only one XML object in the list, the XMLList delegates calls to that object. It basically functions as though it is that XML object. In the following example, lines 2 and 3 are identical because there is only one item: var data:XML = <data><item>Test Value</item.</data>; var value1:String = data.item[0].toString(); var value2:String = data.item.toString(); The first line in the preceding example might seem a bit strange if you are completely new to E4X. It is a new way to define XML objects in ActionScript 3.0 using literals. We'll talk more about literals later in this chapter. QName The QName class, also new to ActionScript 3.0, is used to represent the qualified names of elements and attributes in an XML object. There are two parts to qualified names: The first part is a local name that conforms to XML standards, and the second part is a namespace URI (Uniform Resource Identifier). The namespace is optional. Namespace The Namespace class is used to define XML namespaces. Namespace support is a new feature included in E4X that is also used to define namespaces in your code not related to XML. It's important to understand that this class has multiple uses, only one of which relates to XML. |