XML转换成ArrayCollection

一、
<?xml version="1.0" encoding="UTF-8"?>
<projects>
<node Country="暗暗啊" Gold="10" Silver="20" Bronze="30"/>
<node Country="白斑病" Gold="30" Silver="20" Bronze="10"/>
<node Country="常常厂" Gold="20" Silver="40" Bronze="60"/>
<node Country="赌东道" Gold="50" Silver="30" Bronze="10"/>
<node Country="饿饿额" Gold="15" Silver="18" Bronze="46"/>
<node Country="方法法" Gold="61" Silver="52" Bronze="38"/>
</projects>


<mx:HTTPService id="HTTPService1"
url="charts_ColumnChart.xml"
result="initFile(event)" showBusyCursor="true" method="post"
resultFormat="e4x"/>
  import mx.collections.ArrayCollection;
  import mx.rpc.events.ResultEvent;
  private var ac:ArrayCollection = new ArrayCollection();
  function initFile(event:ResultEvent):void{
     for each(var p:XML in event.result..node){
      var obj:Object=new Object();
      obj.Country=p.@Country;
      obj.Gold=p.@Gold;
      obj.Silver=p.@Silver;
      obj.Bronze=p.@Bronze;
     ac.addItem(obj);
  }
}

 

 

 

二、

 


<?xml version="1.0" encoding="UTF-8"?>
<projects>
<node>
<Country>暗暗a</Country>
<Gold>10</Gold>
<Silver>20</Silver>
<Bronze>30</Bronze>
</node>
<node>
<Country>暗b啊</Country>
<Gold>10</Gold>
<Silver>20</Silver>
<Bronze>30</Bronze>
</node>
<node>
<Country>暗c啊</Country>
<Gold>10</Gold>
<Silver>20</Silver>
<Bronze>30</Bronze>
</node>
</projects>
<mx:HTTPService id="HTTPService2"
url="charts_ColumnChart1.xml"
result="initFile1(event)" showBusyCursor="true" method="post"
resultFormat="e4x"/>
import mx.collections.ArrayCollection;
import mx.rpc.events.ResultEvent;
private var ac1:ArrayCollection = new ArrayCollection();
function initFile1(event:ResultEvent):void{
for each(var p:XML in event.result..node){
var xmlobj:XMLList=new XMLList(p);
ac1.addItem(xmlobj);
}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值