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;

すべての質問を確認したいと思います (質問 1、質問 2、質問 3 以外にもあります)。数字 (給与、ボーナス) を含むものもあれば、含まないものもあります。リスト全体を調べて、答えが数字かどうかを調べ、そうであれば数字を取得する方法を探しています。(そしてそれを使っていくつかの計算を行います)。どうやってやるの?

ありがとう!

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 に答える