代码1(ArrayCollection转为Xml)
- [Bindable]
- public var coll:ArrayCollection = new ArrayCollection
- ([ {label:"北京", num:"1500"}, {label:"上海", num:"1400"},
- {label:"广州", num:"1444"}, {label:"天津", num:"1412"} ]);
- private function arrToXml(arr:ArrayCollection):XML{
- var root:XML = new XML("<root/>");
- for(var i:int = 0;i<arr.length;i++){
- var node:XML = new XML("<node/>");
- node.label= arr[i].label;
- node.num= arr[i].num;
- root.appendChild(node);
- }
- return root;
- }
代码2 (Xml转为ArrayCollection)
- [Bindable]
- private var monitorItemData:XML=
- <root>
- <node label="水果" type="0">
- <item label="苹果" value="1"/>
- <item label="橘子" value="2"/>
- </node>
- <node label="蔬菜" type="0">
- <item label="番茄" value="1"/>
- <item label="土豆" value="2"/>
- <item label="大白菜" value="3"/>
- </node>
- <node label="主食" type="0">
- <item label="面" value="1"/>
- <item label="米" value="2"/>
- </node>
- </root>;
- var data:ArrayCollection = new ArrayCollection();
- var xmlListCollection:XMLListCollection = new XMLListCollection();
- private function xmltoarr(xml:Xml):ArrayCollection{//将XML转换为ArrayCollection类型的数据
- xmlListCollection = new XMLListCollection(xml.children());
- data.source = xmlListCollection.toArray();
- return data;
- }