2011-08-10 20 views
0

からのデータ取得:私は以上のすべての行きたいフレックス - 私はそうのような単純なXML持つXMLリスト

var mylist:XMLList; 

<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を作成しましたが質問(question1、question2、question3以上)があります。それらのいくつかは数字(給料、バウンス)を含み、そしていくつかは含まない。私は答えが数字であるかどうかを問い合わせる全リストを調べる方法を探しています。そうであれば数字を取得します。 (そしてそれで何らかの計算をする)。どうやってやるの?

ありがとうございます!

+2

これはかなりひどく形成されているXML - あなたは本当にタグを持たなければならないことそのようなものの周りに浮かんでいるものの代わりに、個々の質問項目すべてを含んでいます。あなたがスキーマを制御しているなら、私はそれを変更します。 –

+0

私はそれについて何もコントロールしていません:( – aaaa

+0

xmlを作った人に電話をかけて、それらが解雇されたことを教えてください –

答えて

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="{[email protected]}"> 
     <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> 
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 
      } 
     } 
関連する問題