繁体   English   中英

Flex / ActionScript-XML

[英]Flex/ActionScript - XML

我正在尝试阅读下面的xml文件,并在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>

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

但是我不明白。

我的问题是

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

提前致谢

您需要使用e4x ,它是ECMAScript for XML。 e4x就像XPath一样,可以遍历XML文档以查找元素。

这是Adobe的一些文章。

http://learn.adobe.com/wiki/display/Flex/E4X
http://livedocs.adobe.com/flex/3/html/help.html?content=13_Working_with_XML_03.html

查看以下文档中的样本。

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html

一些教程

在这里查看教程
这是另一个教程

        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注释如下:
<!-- comment -->

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM