0

我有一个像这样的简单 xml:

<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>

我创建了一个包含数据的 XMLList:

var mylist:XMLList;

我想复习一下所有的问题(不止 question1、question2 和 question3)。其中一些包含数字(薪水,奖金),而另一些则不包含。我正在寻找一种方法来查看整个列表,查询答案是否为数字,如果是,请获取数字。(并用它做一些计算)。我怎样才能做到这一点?

谢谢!

4

2 回答 2

1

这个循环应该通过那个 xml 并读取所有问题的值并获取数字:

for each (var question:XML in mylist..*) {
            if (question.hasOwnProperty("@question") && !isNaN(question.valueOf())) {
                var value:int = question.valueOf();
                // do calclulations on value
            }
        }
于 2011-08-10T19:37:05.797 回答
0

这应该为您提供所需的所有部件。

<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>
于 2011-08-10T17:43:36.520 回答