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