的Flex /动作 - XML动作、Flex、XML

2023-09-08 15:18:19 作者:說好不流淚

我想读下面的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注释是这样的: <! - 评论 - >

flex in action 三 flex对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 -->