Flex 3处理外部XML的两种方法

本文介绍了两种在Flex中加载和显示XML数据的方法:使用mx:Model和mx:HTTPService组件。通过实例展示了如何配置这些组件并将其与UI元素关联,以便在界面上呈现数据。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

点击这里使用RSS订阅本Blog: title="RSS 2.0" type="application/rss+xml" href="http://feed.feedsky.com/softwave" rel="alternate">

其一,用mx:Model:

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

其二:用mx:HTTPService:

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

其中,XML数据如下:

  1. <?xml version="1.0"?>
  2. <products>
  3.   <product>
  4.     <name>Name</name>
  5.     <price>Price</price>
  6.     <freeship>Free Shipping?</freeship>
  7.   </product>
  8.   <product>
  9.     <name>Whirlygig</name>
  10.     <price>5</price>
  11.     <freeship>false</freeship>
  12.   </product>
  13.   <product>
  14.     <name>Tilty Thingy</name>
  15.     <price>15</price>
  16.     <freeship>true</freeship>
  17.   </product>
  18. <product>
  19.     <name>Really Big Blocks</name>
  20.     <price>25</price>
  21.     <freeship>true</freeship>
  22.   </product>
  23. </products>

请注意数据集的细微差别。


摘自【http://www.5uflash.com/Flex-AIR/flexziliao/list_17_2.html】



<script type="text/javascript" src="http://www.google.com/reader/ui/publish<script type="text/javascript" src="http://www.google.com/reader/public/javascript/user/00697638153916680411/state/com.google/broadcast?n=5&amp;callback=grc_p%28%7bc%3a%22green%22%2ct%3a%22%5cu8fd9%5cu4e9b%5cu6587%5cu7ae0%5cu4e5f%5cu503c%5cu5f97%5cu4e00%5cu770b%22%2cs%3a%22false%22%7d%29%3bnew%20grc"></script>%22%7D%29%3Bnew%20GRC">



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值