HTTPService XML: force ArrayCollections?


i'm loading xml document httpservice.  has annoying behavior.  if source xml looks like:

 

<one>

  <two>thing</two>

</one>

 

then one.two string ("thing").

 

if xml is:

 

<one>

   <two>thing</two>

   <two>another thing</two>

</one>

 

then one.two arraycollection.

 

is there way force first case generate arraycollection?  right have manually check everywhere if 2 arraycollection, if isn't, make new one, etc... seems flex should take care of automatically.

 

-jsd-

hi,

 

checkout below code...this ensure arraycollection in both cases...and need check once whether arrycollection or not , @ other places can avoid check converting arraycollection can directly use arraycollection..

 

<?xml version="1.0" encoding="utf-8"?>
<mx:application xmlns:mx="http://www.adobe.com/2006/mxml" creationcomplete="loadxmldata();" layout="absolute">
<mx:script>
  <![cdata[
   import mx.collections.arraycollection;
   import mx.rpc.xml.simplexmldecoder;
  
   private var arraycollection:arraycollection = new arraycollection();
  
   private function loadxmldata():void
   {
    var xml:xml = new xml(myxml.tostring());
    var xmldoc:xmldocument = new xmldocument(xml);
    var decoder:simplexmldecoder = new simplexmldecoder(true);
    var resultobj:object = decoder.decodexml(xmldoc);
   
    if(resultobj != null)
    {
     if(resultobj.one.two arraycollection)
     {
      arraycollection = resultobj.one.two arraycollection;
     }
     else if(resultobj.one.two string)
     {
      arraycollection.additem(resultobj.one.two);
     }
    }
   }
  
  ]]>
</mx:script>
<mx:xml id="myxml" xmlns="">
  <one>
    <two>thing</two>
  </one>
</mx:xml>

</mx:application>


if post answers question or helps, please kindly mark such.


thanks,

bhasker chari



More discussions in Flex (Read Only)


adobe

Comments

Popular posts from this blog

CS5 Adobe Media Encoder: Encode failed because the source duration is nil.

cf_sql_integer vs cf_sql_bigint vs cf_sql_int??

localhost/joomla15/administrator doesnt work - Joomla! Forum - community, help and support