读书人

flex处置外部的xml

发布时间: 2012-07-15 20:11:29 作者: rapoo

flex处理外部的xml
catalog.xml如下:

<?xml version="1.0"?>
<products>
<product>
<name>数学</name>
<price>Price</price>
<freeship>Free Shipping?</freeship>
</product>
<product>
<name>英语</name>
<price>5</price>
<freeship>false</freeship>
</product>
<product>
<name>中文</name>
<price>15</price>
<freeship>true</freeship>
</product>
<product>
<name>Blocks</name>
<price>25</price>
<freeship>true</freeship>
</product>
</products>


有两中方法:

1、用mx:Model的eee.mxml文件:

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Model id="catalogService" source="catalog.xml" />
<mx:ArrayCollection id="myXC" source="{catalogService.product}"/>
<mx:Repeater id="r" dataProvider="{myXC}" startingIndex="1">
<mx:RadioButton id="Radio" label="{r.currentItem.name}"/>
</mx:Repeater>
</mx:Application>

2、用mx:HTTPService的ddd.mxml文件

<?xml version="1.0"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" initialize="catalogService.send()">
<mx:HTTPService id="catalogService" url="catalog.xml" resultFormat="e4x"/>
<mx:XMLListCollection id="myXC" source="{catalogService.lastResult.product}"/>
<mx:Repeater id="r" dataProvider="{myXC}" startingIndex="1">
<mx:RadioButton id="Radio" label="{r.currentItem.name}"/>
</mx:Repeater>
</mx:Application>

读书人网 >flex

热点推荐