aaaa
aaaa

Reputation: 1

flex - getting data from an xml list

i have a simple xml like so:

<root Name="Bob" isImployed="true">
 <customer Name="Bob" id="12345">was addressed in the shopping mall</customer> 
 <Job-title>Insurance</Job-title> 
 <experience>15</experience> 
 <Question1 question="how much do you make?">35000</Question1> 
 <Question2 question="do you get a yearly bonus?">5000</Question2> 
 <Question3 question="would you be interested in our weekly plan?">yes</Question3>
</root>

i've created an XMLList containing the data:

var mylist:XMLList;

I would like to go over all the questions (there are more than question1,question2 and question3). some of those contain numbers (salary, bouns) and some don't. I am looking for a way to go over the whole list, querying if the answer is a number or not, and if so - get the number. (and do some calculation with it). How can I do that?

Thanks!

Upvotes: 0

Views: 1087

Answers (2)

supercooldude
supercooldude

Reputation: 195

This loop should go thru that xml and read the values of all questions and get the ones that are numbers:

for each (var question:XML in mylist..*) {
            if (question.hasOwnProperty("@question") && !isNaN(question.valueOf())) {
                var value:int = question.valueOf();
                // do calclulations on value
            }
        }

Upvotes: 1

SuperSaiyen
SuperSaiyen

Reputation: 1410

This should give you all the parts you need.

<mx:XML id="someXML" xmlns="">
        <root Name="Bob" isImployed="true">
            <customer Name="Bob" id="12345">was addressed in the shopping mall</customer> 
            <Job-title>Insurance</Job-title> 
            <experience>15</experience> 
            <Question1 question="how much do you make?">35000</Question1> 
            <Question2 question="do you get a yearly bonus?">5000</Question2> 
            <Question3 question="would you be interested in our weekly plan?">yes</Question3>
        </root>
    </mx:XML>
    <mx:List dataProvider="{someXML..@question}">
        <mx:itemRenderer>
            <mx:Component>
                <mx:VBox>
                    <mx:Label text="Question:     {data}" fontWeight="bold" />
                    <mx:Label text="{XML(data).parent()}" />
                    <mx:Label text="Is Number:   {isNaN(XML(data).parent())?'No':'Yes'}" />
                </mx:VBox>
            </mx:Component>
        </mx:itemRenderer>
    </mx:List>

Upvotes: 0

Related Questions