Search code examples
xmlactionscript-3e4x

ActionScript E4X Get Tag Attributes


I am a real newbie when it comes to E4X, so please bear with me. I am working on an ActionScript 3.0 project which I would like to extract all of the attributes from an XML tag.

I have used the XML.attributes() method, but that only returns the value of each attribute/ I would like the to get all of the attribute names and attribute values for a given XML tag.

Could someone please show me as to how I could obtain this?

Thank you for your time,
spryno724


Solution

  • Google is your friend

    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
    }