Reputation: 17348
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
Upvotes: 1
Views: 1053
Reputation: 35830
XML.attributes()
doesn't only return the value, you're just seeing the string serialization of the attributes. Given attr = <foo bar="baz"/>.attributes()[0]
, attr.localname() === "bar"
and attr.toString() === "baz"
.
Upvotes: 0
Reputation: 6402
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
}
Upvotes: 3