'e4x'에 해당되는 글 1건

  1. [2007/07/04] AS3.0 :: XML에 새롭게 추가된 @ (at sign) operator (13)

AS3.0 :: XML에 새롭게 추가된 @ (at sign) operator

[FLASH/Reference]
The first example shows how to use the @ (at sign) operator to identify an attribute of an element:
var myXML:XML = 
<item id = "42">
<catalogName>Presta tube</catalogName>
<price>3.99</price>
</item>;

trace(myXML.@id); // 42
The next example returns all attribute names:
var xml:XML =<example id='123' color='blue'/>
var xml2:XMLList = xml.@*;
trace(xml2 is XMLList); // true
trace(xml2.length()); // 2
for (var i:int = 0; i < xml2.length(); i++)
{
trace(typeof(xml2[i])); // xml
trace(xml2[i].nodeKind()); // attribute
trace(xml2[i].name()); // id and color
}
The next example returns an attribute with a name that matches a reserved word in ActionScript. You cannot use the syntax xml.@class (since class is a reserved word in ActionScript). You need to use the syntax xml.attribute("class"):
var xml:XML = <example class='123'/>
trace(xml.attribute("class")); // 123

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

@ (at sign) 과 Dot Syntax 맘에 든다.
무작정 childNodes로 돌리고 대략 정의내려서 작업했던 시절은 가고~ 좀더 직접적인 접근방식의 XML로써 코드의 양을 상당 줄여주고 효율성을 높였다.
E4X(ECMAScript for XML)의 파워~

2007/07/04 13:38 2007/07/04 13:38