flex - 从 xml 列表获取数据

发布于 2024-11-29 07:00:26 字数 747 浏览 1 评论 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)。其中一些包含数字(工资、奖金),有些则不包含。我正在寻找一种方法来遍历整个列表,查询答案是否是数字,如果是,则获取数字。 (并用它做一些计算)。我怎样才能做到这一点?

谢谢!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无人问我粥可暖 2024-12-06 07:00:26

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

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

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
            }
        }
温柔一刀 2024-12-06 07:00:26

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

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

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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文