3 Replies Latest reply on Aug 27, 2008 7:53 PM by Newsgroup_User

    [Help] XML covert to ArrayCollection

    newhelper
      I have a question about XML covert to ArrayCollection.

      My xml format is as follows:
      //+++++++++++++++++++++++++++++++++++++++++++++++
      <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
      <users>
      <user firstName="Anthony" sex="F" />
      <user firstName="Mark" sex="M" />
      </users>
      //+++++++++++++++++++++++++++++++++++++++++++++++
      The function for HTTPService is as follows
      private var acResult:ArrayCollection;
      private function httpHandle(e:ResultEvent):void {
      //var xmlResult:XML = XML(e.result);
      acResult = (e.result.users.user); //<---------??
      }
      I tried to use e.result.users.user, but it is failed. Any suggestion? or have to write a loop to structure ArrayCollection manually?

      Thx!
        • 1. Re: [Help] XML covert to ArrayCollection
          Level 7

          "newhelper" <webforumsuser@macromedia.com> wrote in message
          news:g937ii$rlh$1@forums.macromedia.com...
          >I have a question about XML covert to ArrayCollection.
          >
          > My xml format is as follows:
          > //+++++++++++++++++++++++++++++++++++++++++++++++
          > <?xml version="1.0" encoding="UTF-8" standalone="no" ?>
          > <users>
          > <user firstName="Anthony" sex="F" />
          > <user firstName="Mark" sex="M" />
          > </users>
          > //+++++++++++++++++++++++++++++++++++++++++++++++
          > The function for HTTPService is as follows
          > private var acResult:ArrayCollection;
          > private function httpHandle(e:ResultEvent):void {
          > //var xmlResult:XML = XML(e.result);
          > acResult = (e.result.users.user); //<---------??
          > }
          > I tried to use e.result.users.user, but it is failed. Any suggestion? or
          > have
          > to write a loop to structure ArrayCollection manually?
          >
          > Thx!

          try

          e.result.user


          • 2. Re:  [Help] XML covert to ArrayCollection
            newhelper Level 1
            yes, I also tried acResult = e.result.user, it does not work.
            It throws "Type Coercion failed: cannot convert XMLList@5e63d61 to mx.collections.ArrayCollection."
            • 3. Re: [Help] XML covert to ArrayCollection
              Level 7

              "newhelper" <webforumsuser@macromedia.com> wrote in message
              news:g94sac$7d5$1@forums.macromedia.com...
              > yes, I also tried acResult = e.result.user, it does not work.
              > It throws "Type Coercion failed: cannot convert XMLList@5e63d61 to
              > mx.collections.ArrayCollection."

              Try something like this:

              var xlc:XMLListCollection = new XMLListCollection(e.result.user);
              acResult = new ArrayCollection(xlc.toArray())

              Is there any reason why you can't just use an XMLListCollection?

              HTH;

              Amy