Flex/ActionScript - XML [英] Flex/ActionScript - XML

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

问题描述

我正在尝试读取以下 xml 文件并获取 Flex/Actionscript 中的名称-值对.

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

示例.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>

我正在尝试使用 XML 的 .name().text() 函数为两个孩子使用以下所有标签名称和值的详细信息

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

但我不明白.

我的问题是,

谁能告诉我如何解析这个xml以获取详细信息每个孩子分别在一个对象中,然后将该对象存储在数组供以后使用?

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 ?

提前致谢

推荐答案

        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());
            }
        }

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

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

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

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