PlayScriptRedux / playscript

PlayScript is an ActionScript compatible compiler and Flash compatible runtime that runs in the Mono/.NET environment
Other
17 stars 9 forks source link

XML.attributes | xml.@* - Implement function and parser enhancement #62

Open sushihangover opened 9 years ago

sushihangover commented 9 years ago

Currently XML.attributes is not implemented

        public function attributes():XMLList {
            throw new System.NotImplementedException();
        }
New Test: as/test-as-XML-Attrubutes-Access.as
// Compiler options: -psstrict-
package {
    public class Foo {
        public static function Main():int {
                var xml:XML=<example id='123' color='blue'/>;

                trace(xml.attributes()[1].name()); //color

                return 0;
        }
    }
}
sushihangover commented 9 years ago

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html

attributes () method
AS3 function attributes():XMLList Language Version: ActionScript 3.0 Runtime Versions: AIR 1.0, Flash Player 9 Returns a list of attribute values for the given XML object. Use the name() method with the attributes() method to return the name of an attribute. Use of xml.attributes() is equivalent to xml.@*.

Returns XMLList — The list of attribute values. More examples

Traversing XML structures Learn more

XML objects Related API Elements

XML.attribute() XML.name() @ operator

Example ( How to use this example )

The following example returns the name of the attribute:

var xml:XML=<example id='123' color='blue'/>
trace(xml.attributes()[1].name()); //color

This example returns the names of all the attributes:

var xml:XML = <example id='123' color='blue'/>
var attNamesList:XMLList = xml.@*;

trace (attNamesList is XMLList); // true
trace (attNamesList.length()); // 2

for (var i:int = 0; i < attNamesList.length(); i++)
{ 
    trace (typeof (attNamesList[i])); // xml
    trace (attNamesList[i].nodeKind()); // attribute
    trace (attNamesList[i].name()); // id and color
} 
sushihangover commented 9 years ago

New Test: as/test-as-XML-Attributes-Operator.as

// Compiler options: -psstrict-
package {
    public class Foo {
        public static function Main():int {

                var xml:XML = <example id='123' color='blue'/>
                var attNamesList:XMLList = xml.@*;

                trace (attNamesList is XMLList); // true
                trace (attNamesList.length()); // 2

                for (var i:int = 0; i < attNamesList.length(); i++)
                {
                    trace (typeof (attNamesList[i])); // xml
                    trace (attNamesList[i].nodeKind()); // attribute
                    trace (attNamesList[i].name()); // id and color
                }

                return 0;
        }
    }
}