flex解析XML
FLEX解析XML过程如下:
XML结构----
[Bindable]
private var ifCurrentXieruData:XMLList = <>
<data>
<if_current_xieru_desc>全部</if_current_xieru_desc>
<if_current_xieru></if_current_xieru>
</data>
<data>
<if_current_xieru_desc>是当月携入(当月指统计月)</if_current_xieru_desc>
<if_current_xieru>1</if_current_xieru>
</data>
<data>
<if_current_xieru_desc>不是当月携入(当月指统计月)</if_current_xieru_desc>
<if_current_xieru>0</if_current_xieru>
</data>
</> ;//areadate
这是一个绑定在combobox上的一个数据源,类型为XMLList(是XML的子类,获取的方式为XML(e.result).children())
我们进行解析的方法如下:
场景是取到值为value的选项,显示在combobox中
private function getIndexString(flag:String,value:String):void{
var xml:XMLList = XMLList(ifCurrentXieru.dataProvider);
for(var i:int = 0, nLen:int = xml.length(); i < nLen; i++)
{
if(value == xml.if_current_xieru[i].text().toString()){
ifCurrentXieru.selectedIndex = i;
break;
}
}