Flex Webservices XML and Array Conversion

I'm currently working on a project involving simple webservices, the webservices return plain XML rather than using SOAP. Personally I prefer SOAP as you get a well defined interface but on this project it was felt that plain XML was less verbose, more efficient and easy to code server side.

Anyway one of the issues with returning XML via HTTPService calls is that when flex converts the XML to objects it treats it as array if there's more than one item of the same name but as a single item (ie not an array) if there's only one item of the same name.

This causes databinding to datagrids or lists to fail.

So how do you get around this issue?


Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Thanks for the code. I was getting an error regarding conversion from Object to ArrayCollection so I modified the code a little:

var data:Object = event.result.users.user

if (data is ArrayCollection) {
   userlist = ArrayCollection(data);
else {
   userlist = new ArrayCollection([data])
# Posted By Mack | 6/2/07 9:20 AM
If data was declared as an ArrayCollection rather than an Object you woudn't need to do this, but there's nothing wrong with doing it that way either.
# Posted By Justin Mclean | 6/2/07 9:48 AM
Thanks for the solution, you saved the day. I have been looking for a solution for quite a while.
# Posted By Henrik | 2/29/08 12:11 AM