this is part of an XML file I retrieve using AS3 E4X:
<links>
<link>
<label>Versions</label>
<href>http://mylink1</href>
</link>
<link>
<label>Configurations</label>
<href>http://myLink2</href>
</link>
</links>
I want to retrieve the values of labels, so I write:
document.links.link.label.text();
This returns VersionsConfigurations. I need this as Array ([Versions, Configurations]) but I would like not to use a loop. Is there any other way?
Well, this is a “don’t try this at home” solution, but here you are. 🙂
You can use E4X search expression to do whatever you want to nodes of an XMLList.
This works as follows:
someXMLList.(expression), where expression is any AS3 code that can access each node’s properties and methods with no need of qualifying their names. For instance, you could do the following:Note that I’m using
text()here with no access.operations. Actually this will return an new XMLList for all nodes, where expression evaluated totrue. Sincetrace()returns void, the resulting list will be empty. Internally there is of course a loop through all nodes of XMLLIst that is created by callingdescendants()(or using..operator).You can construct your array the same way.
That may be useful when performing some complicated searches on an XMLList. However in your case I think you should instead use simple splitting of a string representation or a regular expression as Shane suggests.