Flex中读取外部XML文件

Flex中读取外部本地XML文件,为DataGrid提供数据的示例:

 

MXML文件:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundGradientAlphas="[0.4, 1.0]" backgroundGradientColors="[#9154DD, #6798C2]">
<mx:Model id="ShoppingCartList" source="myData/ShoppingCartList.xml" />
<mx:Panel layout="absolute" right="10" bottom="10" top="255" width="250" title="购物车">
	<mx:DataGrid x="0" y="0" width="230" editable="false" dragEnabled="true" dataProvider="{ShoppingCartList.item}" height="162" bottom="40" top="0">
	<mx:columns>
        <mx:DataGridColumn headerText="Name" dataField="name"/>
	<mx:DataGridColumn headerText="Price" dataField="price"/>
	<mx:DataGridColumn headerText="Number" dataField="number"/>
	</mx:columns>
	</mx:DataGrid>
	     <mx:Button x="172" y="172" label="移除" fontSize="12" bottom="10" right="10"/>
	</mx:Panel>
</mx:Application>

 

提供数据的ShoppingCartList.xml文件,保存在myData/ShoppingCartList.xml下,代码如下:

<ShoppingCartList>
	<item>
		<name>Apple</name>
		<price>2.33</price>
		<number>12</number>
	</item>
	<item>
		<name>Computer</name>
		<price>2043.3</price>
		<number>1</number>
	</item>
	<item>
		<name>TV</name>
		<price>3000</price>
		<number>2</number>
	</item>
	<item>
		<name>Camera</name>
		<price>2311.23</price>
		<number>1</number>
	</item>
	<item>
		<name>Keyboard</name>
		<price>3.3</price>
		<number>12</number>
	</item>
	
</ShoppingCartList>

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值