<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="absolute" width="900" height="700" fontSize="12"
creationComplete="init()" xmlns:s="library://ns.adobe.com/flex/spark">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable]private var shijxml:XML;
private function init():void{
shijxml = arrToXml(exams);
}
[Bindable]
public var exams:ArrayCollection = new ArrayCollection(
[{sjtitle:"数据结构第一章", kemu:"数据结构",shijID:"sj000" ,num:"30"},
{sjtitle:"数据结构第二章", kemu:"数据结构",shijID:"sj001" ,num:"30"},
{sjtitle:"组成原理第一章", kemu:"组成原理",shijID:"zc000" ,num:"50"},
{sjtitle:"组成原理第二章", kemu:"组成原理",shijID:"zc001" ,num:"30"} ]);
private function arrToXml(arr:ArrayCollection):XML{ //形成xml内容
var root:XML = new XML("<root/>");
for(var i:int = 0;i<arr.length;i++){
var node:XML = new XML("<node/>");
node.sjtitle = arr[i].sjtitle;
node.kemu= arr[i].kemu;
node.shijID= arr[i].shijID;
node.num= arr[i].num;
root.appendChild(node);
}
return root;
}
protected function confirm_clickHandler(event:MouseEvent):void
{
var file:FileReference=new FileReference();
trace(shijxml);
file.save(shijxml,"test.xml");
}
]]>
</mx:Script>
<s:VGroup width="100%" height="100%">
<mx:Panel width="100%" height="40%" >
<mx:DataGrid height="100%" width="50%" dataProvider="{exams}">
</mx:DataGrid>
</mx:Panel>
<mx:Button id="confirm" click="confirm_clickHandler(event)" label="生成xml文件"/>
</s:VGroup>
</mx:Application>
layout="absolute" width="900" height="700" fontSize="12"
creationComplete="init()" xmlns:s="library://ns.adobe.com/flex/spark">
<mx:Script>
<![CDATA[
import mx.collections.ArrayCollection;
import mx.controls.Alert;
[Bindable]private var shijxml:XML;
private function init():void{
shijxml = arrToXml(exams);
}
[Bindable]
public var exams:ArrayCollection = new ArrayCollection(
[{sjtitle:"数据结构第一章", kemu:"数据结构",shijID:"sj000" ,num:"30"},
{sjtitle:"数据结构第二章", kemu:"数据结构",shijID:"sj001" ,num:"30"},
{sjtitle:"组成原理第一章", kemu:"组成原理",shijID:"zc000" ,num:"50"},
{sjtitle:"组成原理第二章", kemu:"组成原理",shijID:"zc001" ,num:"30"} ]);
private function arrToXml(arr:ArrayCollection):XML{ //形成xml内容
var root:XML = new XML("<root/>");
for(var i:int = 0;i<arr.length;i++){
var node:XML = new XML("<node/>");
node.sjtitle = arr[i].sjtitle;
node.kemu= arr[i].kemu;
node.shijID= arr[i].shijID;
node.num= arr[i].num;
root.appendChild(node);
}
return root;
}
protected function confirm_clickHandler(event:MouseEvent):void
{
var file:FileReference=new FileReference();
trace(shijxml);
file.save(shijxml,"test.xml");
}
]]>
</mx:Script>
<s:VGroup width="100%" height="100%">
<mx:Panel width="100%" height="40%" >
<mx:DataGrid height="100%" width="50%" dataProvider="{exams}">
</mx:DataGrid>
</mx:Panel>
<mx:Button id="confirm" click="confirm_clickHandler(event)" label="生成xml文件"/>
</s:VGroup>
</mx:Application>