flex中xml转化为array实例
本文共两个文件:translate.mxml 和 mapmarking.xml
1、translate.mxml
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/halo"
minWidth="1024" minHeight="768">
<fx:Script>
<![CDATA[
//xml translate array
public function xmlToArr(xmlObj:XML):Array{
var toArr:Array = new Array();
for(var i:uint = 0; i < xmlObj.site.length(); i++){
toArr.push({pid: xmlObj.site[i].id,
province: xmlObj.site[i].province,
city: xmlObj.site[i].city,
updName: xmlObj.site[i].station,
latitude: xmlObj.site[i].ypos[0],
longitude: xmlObj.site[i].xpos,
telephone: "110"
});
}
return toArr;
}
//parse the array
private function arrParse():void{
var arr:Array = xmlToArr(xmlID);
for(var i:int = 0; i < arr.length; i++){
trace(arr[i].updName + "========" + arr[i].longitude);
}
}
]]>
</fx:Script>
<mx:Button id="butID" horizontalCenter="0" fontSize="18"
label="xml translate array" click="arrParse();"/>
<fx:Declaration
相关文档:
string GetXmlByDataTable()
{
string xmlstr;
string sql = "select top 10 * from BasicInfo";
DataTable dt = idb.ReturnDataTable(sql);
&nb ......
1. Jaxp 解析xml文件 Dom方式
<?xml version="1.0" encoding="gbk"?>
<students>
<student id="001">
<name>张三</name>
<age>25</age>
</student>
<student id="002">
<name>李四</name>
& ......
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute">
<mx:Script><!--[CDATA[import mx.collections.ArrayCollection;
public var a1:ArrayCollection = new ArrayCollection ([{ Region:"Region1",Territory:"Territory1",Ter ......
用过FLEX中String类型的朋友可能知道,replace这个方法并不过替换所有内容。那么我们需要替换所有内容怎么办?只有自己动手,丰衣足食咯,呵呵。言归正专,有两种方法,一种是利用Array的方式,另一种是利用正则去替换。
/**
* StringReplaceAll
* @param source:String 源数据
* @param find:String 替换对象 ......
研究E4X与Flex的关系,所以打算总结一下,有说的不对的地方,还请大家多多原谅。
一、最简单模式:Flex通过httpservice和dataProvider进行数据传输
Xml格式如下:
<?xml version="1.0" encoding="utf-8" ?>
<Result>
<NodeA>value1</NodeA>
<NodeB>valve2</NodeB>
…&he ......