`
hewei870723
  • 浏览: 62043 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

XML转换成ArrayCollection

    博客分类:
  • FLEX
XML 
阅读更多

一、
<?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);
}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics