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

Using Arduino Uno R3 to bootload the atmega328-PU (non pico)

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

How to update nested ListCollectionViews?