Is there an alternative way to filter xml elements without the E4X syntax?

105 Views Asked by At

I am trying to compile some old actionscript code (part of flash app) to JS using Jangaroo. Jangaroo does not support the E4X syntax and it fails at things like the double-dot operator .. or the brackets filters a.(CONDITION). So I need to rewrite those portions of code using plain ActionScript.

For the double-dot operator, I used the instead the method descendants() but I could not find alternative way to write the brackets filter.

Here is the original code I had:

B = xml..destination.(@id == someId)

I wrote it now:

B = xml.descendants("destination").(@id == someId)

But I still want to remove .(@id == someId).

I am thinking of something like:

if (xml.descendants("destination").attribute("id") == someId)
{
B = xml.descendants("destination")
}

Is this possible?

1

There are 1 best solutions below

1
mockingjay On

So here is how I proceeded. I have not tested its functionality, but the compiler passed it.

var destinations:XMLList = null;
for each (var elm in xml.descendants("destination") )
{
 if ( elm.attribute("id") == someId )
 {
    destinations += elm;
 }
}