Flex xml的实用操作


  XML类包含用于处理XML对象的工作方法和属性。 XML类(以及XMLList,命名空间和QName类)基于ECMAScript中定义的XML(E4X)规范(ECMA - 357第2版)标准,实现了强大的XML处理在。使用toXMLString()方法返回的XML对象的字符串表示不论XML对象具有简单内容还是复杂内容。
  但是flex的xml操作还不支持xquery等简便、强大的查询操作,但是对于一般的xml结点读取、属性读取、结点查找、属性查找、结点遍历等还是完全可以胜任。
  本文提供了一个xml操作的实用Demo,主要有下述3部分内容:
  1)构建xml;
  2)xml结点读取、属性读取、结点遍历等;
  3)用户可以利用..先得到所有结点列表xmllist,然后遍历该xmllist查找任何元素、结点。   flex/spark"                xmlns:mx="library://ns.adobe.com/flex/mx" width="800"                height="600" creationComplete="init()" fontSize="11">                                                                                                                                                              11 Main St.                             San Francisco                             CA                             98765                                                                                                                                                       99 Broad St.                             Newton                             MA                             01234                                                                   ;               //显示xml               XML.prettyIndent = 2;    //设置xml缩进量               txtSrc.text = employees.toXMLString();            }                        protectedfunction btnShow_clickHandler(event:MouseEvent):void            {               var  output:String = "";               //employees.employee[0].address.zip, 98765               output+="employees.employee[0].address.zip: "+employees.employee[0].address.zip+"\r\n\r\n";               //employees.employee[1].@ssn, 789-789-7890               output+="employees.employee[1].@ssn: "+employees.employee[1].@ssn+"\r\n\r\n";               //employees.employee.name,                //               output+="employees.employee.name: "+employees.employee.name+"\r\n\r\n";               //employees..zip[0], 98765               output+="employees..zip[0]: "+employees..zip[0]+"\r\n\r\n";               //employees..@ssn[1], 789-789-7890               output+="employees..@ssn[1]: "+employees..@ssn[1]+"\r\n\r\n";               //employees..name,                //               output+="employees..name: "+employees..name+"\r\n\r\n";               //employees.employee[0].address.*, 11 Main St.                //San Francisco               //CA               //98765               output+="employees.employee[0].address.*: "+employees.employee[0].address.*+"\r\n";                 txtOpreate.text = output;              }        ]]>                    
  
  
  width="70" right="80" toolTip="请输入员工的ZIP" text="01234"/>
  width="70" right="3" toolTip="查找" label="查找"
  click="btnQuery_clickHandler(event)"/>
  
  width="30%" height="100%"/>
  width="70%" height="100%"/>
  
  

你可能感兴趣的:(Flex)