Cool, I also did it with e4x now, works much better,

I did it with a static method in PersonVO

public static function createFromXML(personXML:XML):PersonVO
{
.....
}

Thanks


--- In [email protected], "Kenneth Sutherland"
<[EMAIL PROTECTED]> wrote:
>
> I'd do it like this. Not tested the below code, but it's the same as
> stuff I've used before that works fine. Just pass the XML that you get
> returned to the function. Slightly different approach but should be
good
> for any number of XML entries
>
>
>
> private function populatePerson(xml : XML) : void {
>
>                   if(xml){
>
>
>
>                         persons = new ArrayCollection();
>
>                         var personList : XMLList = xml.person;
>
>                         for each (var person : XML in personList ) {
>
>                               persons.addItem(new PersonVO(person));
>
>                         }
>
> }
>
> }
>
>
>
> Then create your PersonVO like so
>
>
>
> [Bindable]
>
>       public class PersonVO
>
>       {
>
>             public var name : String;
>
>             public var pid : Number;
>
> public var cloneableData : XML;
>
>             public function PersonVO(xml : XML)
>
>             {
>
>                   if(xml){
>
>                         pid = xml.pid;
>
>                         name = xml.name;
>
>                         cloneableDate = xml;//you don't need this but
> with complex objects saving the XML makes cloning very easy.
>
>                   }
>
>             }
>
>
>
>       }
>
>
>
> Kenneth.
>
>
>
> From: [email protected] [mailto:[EMAIL PROTECTED]
On
> Behalf Of max.bruchmann
> Sent: 26 August 2008 09:09
> To: [email protected]
> Subject: [flexcoders] xml contains list with sometimes only one
element
>
>
>
> Hi,
> I have a http service that returns me a list of persons:
>
> <persons>
>
> <person>
> <pid>1</pid>
> <name>Foo</name>
> </person>
>
> <person>
> <pid>2</pid>
> <name>Bar</name>
> </person>
>
> </persons>
>
> Now my result handler looks like that:
>
> var persons:ArrayCollection;
> function personsResult(resultEvent:ResultEvent):void {
>
>  persons = resultEvent.result.persons.person;
>
> }
>
> BUT when my http service would contain only one person entry:
>
> <persons>
>
> <person>
> <pid>1</pid>
> <name>Foo</name>
> </person>
>
> </persons>
>
> then the resultEvent.result.persons.person is no longer from type
> ArrayCollection, because it's already the "person object"
> so my resultHandler has to look like this
>
> var persons:ArrayCollection;
>
> function personsResult(resultEvent:ResultEvent):void {
>
> if(resultEvent.result.persons.person is ArrayCollection){//for
multiple
> entries
>
> persons = resultEvent.result.persons.person;
>
> }else if(resultEvent.result.persons.person !=null){//if only one entry
>
> persons = new ArrayCollection([resultEvent.result.persons.person]);
>
> }
>
> }
>
> But it's really a pain, writing this for all resulthandler where you
> might receive a list with only on entry, so have I overseen the
regular
> easy way for that or do I have to do this every time?
>
> thanks in advance
> max
>
>
>
>
>
> Disclaimer
>
------------------------------------------------------------------------\
-------------------
> This electronic message contains information which may be privileged
and confidential. The information is intended to be for the use of the
individual(s) or entity named above. If you are not the intended
recipient, be aware that any disclosure, copying, distribution or use of
the contents of this information is prohibited. If you have received
this electronic message in error, please notify us by telephone on 0131
476 6000 and delete the material from your computer.
> Registered in Scotland number: SC 172507.
> Registered office address: Quay House 142 Commercial Street Edinburgh
EH6 6LB.
>
> This email message has been scanned for viruses by Mimecast.
>
------------------------------------------------------------------------\
-------------------
>


Reply via email to