2007年5月15日星期二

XML: @ Operator for Attributes

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 = name="senocular" id="2867" />;
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 = name="senocular" id="2867" />;
var atts:XMLList;

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

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

0 评论: