3 Replies Latest reply on Sep 10, 2009 10:25 PM by oli4dejonge

    Loading multiple XML files into one XMLList

    Handycam Level 1

      I am working on an app where I will load a list of recipes.  Each recipe is an XML file.  I would have an XML file that lists the filenames that need to be loaded.  I am assuming in can use one HTTPService and loop through this list, and set the url and do myService.send() until all the xml files have been loaded and concatenated into one xml list. True?


      My main question here is how do I load each XML file and add it to the same XMLList?


      Assume each XML file's root tag is <recipe>.  I want to create an XMLList with the root  <recipes> with each <recipe> as a first child.



        • 1. Re: Loading multiple XML files into one XMLList
          Peter deHaan Level 4

          Instead of XMLList, I'd suggest using XMLListCollection. And then as each XML file is loaded, add its contents to the collection using the addItem() method.



          • 2. Re: Loading multiple XML files into one XMLList
            SunilAdobe Adobe Employee

            Why don't you use the Data centric workflows which will help you to deal with multiple XML files as AS objects? Something like this


            1. Create a HTTPService using Data menu -> Connect to HTTPService

            2. create a operation getRecipe and enter your URL example URL: http://myserver/recipe?name=recipename

            3. Use Configure Return Type to tell that this method returns a Recipe class

            4. Use DataBinding to bind the result of this to a DataGrid


            Call the following in a loop and


            recipeName = myRecipes+ // All of your recipe names, Recipe is a ArrayCollecition

            Recipe.setAt(i) = Svc1.getRecipe(recipeName);


            At the end you would have a Recipe[]


            This is one of the ways you could work instead of having a XMLListCollection and use e4x etc. to go through your collection.


            Let us know if this helps, or you are looking for something else.




            • 3. Re: Loading multiple XML files into one XMLList
              oli4dejonge Level 1

              >My main question here is how do I load each XML file and add it to the same XMLList?


              I assume that you have to much data to load at once. I would load a recipe each time you click on it in a list when you want to see or edit it. Use a HTTPService with prop resultFormat set to 'array' for the whole list and to 'object' for a recipe details.

              1. When receiving the result of the list of recipes the xml is deserialized into an ArrayCollection with ObjectProxies.
              2. When receiving the result of recipe details I would find and replace the orginal object the retrieved ArrayCollection with recipes.setItemAt(newDetailRecipe, recipes.getItemIndex(compactRecipe)); The compact Recipe you kept waiting for the result to return from your http service.
              This is just a simple solution when you work with ObjectProxies to store your data in. More advanced would be if you would serialize your data into classes and replace the objects in the list based on a ID