开发者

faster way to change xml to array(grails to flex)

开发者 https://www.devze.com 2022-12-27 22:46 出处:网络
I have a large xml passed from grails to flex.When flex receives the xml, it converts the xml into an associative array object. Given the large xml file, it takes too long to complete the loop, is the

I have a large xml passed from grails to flex. When flex receives the xml, it converts the xml into an associative array object. Given the large xml file, it takes too long to complete the loop, is there any way in flex to make conversion faster? Below is my sample code.

<xml>
   <car>
      <model>Vios</model>
      <type>Sedan</type>
      <color>Blue</color>
   </car>
   <car>
      <model>Camry</model>
      <type>Luxury</type>
      <color>Black</color>
   </car>
</xml>

*converted to the flex associative array below.*
[Vios].type = Sedan
      .color = Blue
[Camry].type = Luxury
       .color = Black

*Belo开发者_开发知识库w is a code I used in flex to convert the xml to the associative array object*
var tempXML=xml.children()
var tempArray:Array= new Array()
for(var i:int=0;i<tempXML.length();i++)
{
   tempArray[tempXML[i].@model]= new Object();
   tempArray[tempXML[i].@model].color = tempXML[i].@color.toString();
   tempArray[tempXML[i].@model].type = tempXML[i].@type.toString();
}


You can set the HTTPService resultFormat to array. Than you should get an array straight away (parsed by Flex, it still may take some time)

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号