Yes, "MyVO" would be a custom object that uses strongly typed
properties.  This approach it the ideal from a performance standpoint,
since access of strongly typed property values is significantly faster
that either dynamic object properties, or XML.

 

The blog example you referenced in the other post produces an
ArrayCollection of XML nodes.  While this is ok, it kinda does not make
much sense.  If XML is ok for the items in the collection, just use
XMLListCollection.  A loop is not necessary.  But this does not provide
the advantages of a VO (ValueObject), which, in addition to the
performance benefits, allows you to have calculated fields, and special
methods like the "fill" method I alluded to earlier.

 

Note, I use XML almost always, unless I need special work in the item
object.  I have not had any performance issues with XML.  This is
usually reported when scrolling with hundreds of visible itemrenderers

 

Tracy

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of oneworld95
Sent: Tuesday, October 28, 2008 3:50 PM
To: [email protected]
Subject: [flexcoders] Re: Read XML data in as ArrayCollection

 

What is the "MyVO"? Is that a custom object class? Thanks.

--- In [email protected] <mailto:flexcoders%40yahoogroups.com>
, "Tracy Spratt" <[EMAIL PROTECTED]> wrote:
>
> Please, do, the default resultFormat is evil ;)
> 
> 
> 
> Here is a quick, untested start.
> 
> _acPremiums = new ArrayCollection()
> 
> var xmlResult:XML = XML(event.result);
> 
> var xlPremiums:XMLList = xmlResult.premium; //or xmlResult.children();
> 
> var xmlPremium:XML
> 
> var voNew:MyVO;
> 
> for () var i:int=0;i<xlPremiums.length();i++) {
> 
> xmlPremium = xlPremiums[i];
> 
> voNew = new MyVO;
> 
> voNew.fill(xmlPremium); //assumes a fill method. You could also
> simply assign the vo properties here
> 
> _acPremiums.addItem(voNew);
> 
> }
> 
> 
> 
> Tracy
> 
> 
> 
> 
> 
> ________________________________
> 
> From: [email protected] <mailto:flexcoders%40yahoogroups.com>
[mailto:[email protected] <mailto:flexcoders%40yahoogroups.com>
] On
> Behalf Of oneworld95
> Sent: Tuesday, October 28, 2008 2:55 PM
> To: [email protected] <mailto:flexcoders%40yahoogroups.com> 
> Subject: [flexcoders] Re: Read XML data in as ArrayCollection
> 
> 
> 
> Hi, Tracy. Hadn't thought about that. I'll work on implementing your
> suggestion. Thanks.
> 
> --- In [email protected]
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> , "Tracy Spratt" <tspratt@> wrote:
> >
> > That only works because the default resultFormat causes Flex to
cnvert
> > your xml into a nested structure of dynamic objects. One result of
is
> > is that child groups are converted to Array.
> > 
> > 
> > 
> > I advise you do not do this. You lose the benefits of e4x
expressions,
> > and wind up with loosely typed objects everywhere. The conversion
> > always happens, so you do not gain any performance. Also the
> conversion
> > modifies your data, turning strings into numbers where it can, and
> stuff
> > like that. 
> > 
> > 
> > 
> > You will be better served in the long run if you simply loop over
the
> > XMLList and assign the attribute or child values to an instance of a
> > strongly typed value object. 
> > 
> > 
> > 
> > Tracy
> > 
> > 
> > 
> > 
> > 
> > 
> > 
> > ________________________________
> > 
> > From: [email protected]
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> [mailto:[email protected]
<mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com>
> ] On
> > Behalf Of oneworld95
> > Sent: Tuesday, October 28, 2008 2:19 PM
> > To: [email protected] <mailto:flexcoders%40yahoogroups.com>
<mailto:flexcoders%40yahoogroups.com> 
> > Subject: [flexcoders] Re: Read XML data in as ArrayCollection
> > 
> > 
> > 
> > Never mind! Figured it out:
> > 
> > arrCol = event.result.premiums.premium as ArrayCollection
> > 
> > Also took off the resultFormat from the HTTPService call.
> > 
> > --- In [email protected]
<mailto:flexcoders%40yahoogroups.com> 
> <mailto:flexcoders%40yahoogroups.com>
> <mailto:flexcoders%40yahoogroups.com>
> > , "oneworld95" <oneworld95@> wrote:
> > >
> > > Hi. I've got a Flex app that receives XML (resultFormat = "e4x")
> data
> > > from a servlet in this format,
> > > 
> > > <premiums>
> > > <premium id="ABCDEF01" startcount="0" currentcount="0">
> > > <category>CD</category>
> > > <description>The CD Description</description>
> > > <image id="3095">
> > > <filename>ABCDEF01__1225202763673.jpg</filename>
> > > </image>
> > > </premium>
> > > <premium id="DEFGH01" startcount="0" currentcount="0">
> > > <category>DVD</category>
> > > <description>DVD Description</description>
> > > <image id="3078">
> > > <filename>DEFGH01__1225132169948.jpg</filename>
> > > </image>
> > > </premium>
> > > </premiums>
> > > 
> > > I need to convert it to an ArrayCollection and then an array to
> > > manipulate the results (using the slice method). Any solutions?
> > Thanks.
> > >
> >
>

 

Reply via email to