1 Reply Latest reply on Dec 26, 2008 10:24 AM by ntsiii

    Convert XML to ArrayCollection

    Johnking08 Level 1
      I have XML data from remote server in this format:
      <age> 20</age>
      <age> 21</age>
      <age> 17</age>

      I need to an ArrayCollection in this form:
      [["John Smith", "20, "M"],
      ["Mike Brown", 21, "M"]
      ["Mary Collin", 17, "F"]]

      Can any help?
        • 1. Re: Convert XML to ArrayCollection
          ntsiii Level 3
          First, why not use XMLListCollection?
          var xmlResult:XML = event.result as XML:
          var xlcUsers:XMLListCollection = new XMLListCollection(xmlResult.user);

          An ArrayCollection of Arrays has few benefits over XLC. (Arrays are not bindable, for instance)

          But if you insist, you can do:
          var xmlResult:XML = event.result as XML:
          var acUsers:ArrayCollection = new ArrayCollection()
          var xlUsers:XMLList = xmlResult.user;
          var xmlUser:XML;
          for (var i:int=0;i<xlUsers;i++) {
          xmlUser = xlUsers[ i ];
          acUsers.addItem([xmlUser.fname.text(),xmlUser.age.text(),xmlUser.sex.text() ])