Search code examples
actionscript-3e4x

E4X, filter to retrieve subnode value


this is a small piece of a bigger XML:

<menu first="modelID">
        <model>
            <id>modelID</id>
            <nome>Name</nome>
            <cover type="img">./img/cover.png</cover>
            <sub value="Images|Audio" />
        </model>
        <model>
            <id>modelID2</id>
...
</model>

Using E4X I easily retrieve the value from the menu "first" attribute and I save it to a variable (firstModel).

Now I want to retrieve the cover type and the cover text() of the node whose id equals to firstModel. How can I do? Is this possible?


Solution

  • var firstModel : String = "modelID"; //your parsed value here
    trace(a.model.(id == firstModel).cover.@type);
    trace(a.model.(id == firstModel).cover);
    


    output:

    [trace] img
    [trace] ./img/cover.png