Joel
Joel

Reputation: 3176

How to get all the xml nodes that contain a certain childnode with a certain value in as3?

I'm trying to work with XML in flash here and ran into an issue. I need to collect all the nodes in an XMLList that contains a certain childnode with a certain value. For example, from the XML below I just want to get the ''product'' nodes that have 1 as a value for ''amount'', i.e product 3 and 5.

And it's not a typo for product 3... ;(

<xml>
    <product>
        <title>Product 1</title>
        <amount>4</amount>
    </product>
    <product>
        <title>Product 2</title>
        <amount>4</amount>
    </product>
    <product>
        <title>Product 3</title>
        <amount>7</amount>
        <amount>1</amount>
    </product>
    <product>
        <title>Product 4</title>
        <amount>4</amount>
    </product>
    <product>
        <title>Product 5</title>
        <amount>1</amount>
    </product>
</xml>

Upvotes: 1

Views: 320

Answers (2)

weltraumpirat
weltraumpirat

Reputation: 22604

var list : XMLList = xml.product.(amount.(valueOf() == 1).length() > 0);

Upvotes: 1

Manish
Manish

Reputation: 3522

If xml is the XML object above, then:

var xmlList:XMLList = xml.product.(amount == 1);
trace(xmlList.toString());

Upvotes: 0

Related Questions