Actionscript 3: Examples of accessing XML attributes
February 08, 2009
ActionScript3 | Flash

Another item I need to keep looking up: how to get the attributes of an XML item.

Here, per the ever-helpful Senocular, is the definitive note on the subject.


E4X (XML used in ActionScript 3) has new operators to access values in XML. One operator is the @ operator which accesses attributes. It can be used in place of the attribute() (Top level XML.attribute()) method for obtaining attribute values. Ex:

ActionScript Code:


var myXML:XML = ;
trace(myXML.attribute("name")); // senocular
trace(myXML.attribute("id")); // 2867
trace(myXML.@name); // senocular
trace(myXML.@id); // 2867


You can also use an asterisk (*) with the @ operator to get a list of all attributes associated with an XML node in the form of an XMLList object. This is equivalent to the attributes() (Top level XML.attributes()) method. Ex:

ActionScript Code:


var myXML:XML = ;
var atts:XMLList;

atts = myXML.attributes();
trace(atts.toXMLString());
/* Output:
senocular
2867
*/
atts = myXML.@*;
trace(atts.toXMLString());
/* Output:
senocular
2867
*/

From Kirupa.com forums: XML: @ Operator for Attributes

Ads by Google

Posted by ellen at February 08, 2009 04:10 PM


Ads by Google

 RSS   |   Contact Me

Ads by Google

Ads by Google