---
title: "flex解析XML"
author: "zjkilly"
date: "2011-04-02T18:12:58Z"
tags: ["Flex", "XML", "数据结构"]
categories: ["Web前端"]
slug: "flex-xml"
draft: false
lastmod: "2011-04-02T18:12:58Z"
id: 985120
url: "https://zjkilly.iteye.com/blog/985120"
---

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;
        }
      }
```