的Flex /动作 - XML [英] Flex/ActionScript - XML

查看:156
本文介绍了的Flex /动作 - XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想读下面的xml文件并获得的Flex / ActionScript中的名称 - 值对。

sample.xml中

 < ABC>
  < XYZ> //第一个孩子
    < ID> < / ID>
    <宽> 10 LT; /宽>
    <高> 10 LT; /身高>
    <名称> PERSON1< /名称>
  < / XYZ>
  < XYZ> //老二
    < ID> < / ID>
    <宽> 20℃/宽度GT;
    <高> 20℃/身高>
    <名称> PERSON2< /名称>
   < / XYZ>
< / ABC>
 

我尝试使用下面的所有变量名和值的详细信息为使用这两种孩子的。名称()的.text() XML功能

但我没有得到它。

我的问题是,

  

谁能告诉我如何解析这个XML,以获得详细信息   分别在对象中的每个孩子在一个对象,然后店   数组供以后使用?

在此先感谢

解决方案

  VAR XML:XML =
            < ABC>
                < XYZ> //第一个孩子
                    < ID> < / ID>
                    <宽> 10 LT; /宽>
                    <高> 10 LT; /身高>
                    <名称> PERSON1< /名称>
                < / XYZ>
                < XYZ>
                    < ID> < / ID>
                    <宽> 20℃/宽度GT;
                    <高> 20℃/身高>
                    <名称> PERSON2< /名称>
                < / XYZ>
            < / ABC取代;
        //获取名为XYZ的儿童名单
        VAR孩子:返回XMLList = xml.XYZ;
        每个(VAR孩子:XML儿童)
        {
            跟踪(child.name());
            //获取内儿童名单(附任何名称)
            每个(VAR道具:XML在child.children())
            {
                //你需要从内儿童的文字,所以这里是
                迹线(\ t的+ prop.name()+=+ prop.text());
            }
        }
 

请注意,您的评论(//第一个孩子)将成为在子列表为空名称文本节点。
在XML注释是这样的:
<! - 评论 - >

I am trying to read the below xml file and get the name-value pairs in Flex / Actionscript.

Sample.xml

<ABC>
  <XYZ>               // First child
    <id> </id>
    <width> 10 </width>
    <height> 10 </height>
    <name> Person1 </name>
  </XYZ>
  <XYZ>              // Second child
    <id>  </id>
    <width>  20 </width>
    <height> 20 </height>
    <name> Person2 </name>
   </XYZ>
</ABC>

I am trying to use the following all tag name and value details for both childs using .name() and .text() function of XML

But I am not getting it.

My question is,

Can anyone please tell me how to parse this xml to obtain the details of each child separately in an object and then store that object in array for later use ?

Thanks in advance

解决方案

        var xml:XML =
            <ABC>
                <XYZ>               // First child
                    <id> </id>
                    <width> 10 </width>
                    <height> 10 </height>
                    <name> Person1 </name>
                </XYZ>
                <XYZ>
                    <id>  </id>
                    <width>  20 </width>
                    <height> 20 </height>
                    <name> Person2 </name>
                </XYZ>
            </ABC>;
        // Get list of children named XYZ
        var children:XMLList = xml.XYZ;
        for each (var child:XML in children)
        {
            trace(child.name());
            // Get list of inner children (with any name)
            for each (var prop:XML in child.children())
            {
                // You need text from inner children, so here it is
                trace("\t" + prop.name() + " = " + prop.text());
            }
        }

Note that your comment (// First child) will become text node with null name in child list.
Comments in XML are like this:
<!-- comment -->

这篇关于的Flex /动作 - XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆