2 Replies Latest reply on May 16, 2008 1:27 PM by ntsiii

    moving from XML HTTPService to local XML?

    davefeldman
      I'm building an AIR app with Flex 3. The current version gets some XML data over HTTP using an HTTPService and, since the result comes down as an Array of objects, dumps it into an ArrayCollection before passing it to the UI. I want to move that particular data set into a local XML file that will be bundled in the app itself, with minimal code change.

      I expected this to be easy but it's proving extremely difficult. Using the File and FIleStream objects I can generate an XML object, but there's no easy way to turn that into an ArrayCollection that I can see. I tried turning it into an XMLList and then an XMLListCollection, but even after inspecting it in Flex Builder I can't figure out how to address it properly, and indeed the innards still seem to be XML objects rather than XMLLists or Arrays.

      To be more specific about that last point: my XML file has a root object named feed, with a number of entry objects inside it. After turning it into an XML object and inspecting it, I see a <feed> object inside the XML object, with a bunch of <entry> objects inside that. But when I turn it into an XMLListCollection I can't figure out how to address the array of <entry> objects. Every permutation I've tried failed.

      And even setting that aside, much of my existing code assumes an ArrayCollection object with an array source...so ideally I'd love a way just to take the local XML file and turn it into the same ArrayCollection it turned into when accessed as an HTTPService.

      Any help would be appreciated. Thanks.
        • 1. Re: moving from XML HTTPService to local XML?
          camfieldaj
          We may be talking apples and oranges here, but in my Flex apps I do:

          <mx:HTTPService id="hsGetStuff"
          url=" http://servername/folder/filename.xml"
          resultFormat="e4x"
          result="GetStuffResultHandler(event);"
          fault="GetStuffFaultHandler(event);">
          </mx:HTTPService>

          <mx:XMLListCollection id="lc" source="{hsGetStuff.lastResult.user}" />

          where xml is <users>
          <user>
          <name></name>
          </user>
          </users>

          dataprovider for datagrid is lc.

          xml file is produced by a cron. But you could have it passed back to you directly, too.
          • 2. Re: moving from XML HTTPService to local XML?
            ntsiii Level 3
            To access individual items in an XMLListCollection, use getItemAt()

            Those items are XML nodes. Note, the line between XMLand XMLList is very fine. In many cases they are interchangeable.

            The framework includes the SimpleDecoder, something like that, that converts xml into an object tree, but you probably don't want that.

            If you don't want to work with XML, manually loop over the xml nodes and build an ArrayCollection of strongly typed VOs. This is the ideal from a performance standpoint.

            Tracy