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

来源:互联网 发布:淘宝算命 编辑:程序博客网 时间:2024/05/16 19:29
点击这里使用RSS订阅本Blog:

其一,用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/publisher.js"></script><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>



<script type="text/javascript"><!--google_ad_client = "pub-7343546549496470";google_ad_width = 468;google_ad_height = 60;google_ad_format = "468x60_as";google_ad_type = "image";//2007-07-26: CSDNgoogle_ad_channel = "6063905817";google_color_border = "6699CC";google_color_bg = "E6E6E6";google_color_link = "FFFFFF";google_color_text = "333333";google_color_url = "AECCEB";google_ui_features = "rc:6";//--></script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"></script>
原创粉丝点击