2 Replies Latest reply on May 8, 2008 7:12 AM by Handycam

    Converting an XML Array to a multi-level array

    Handycam Level 1
      I have an array assigned to a data grid such as:

      private var myIngredients:Array = new Array(
      <item ln1="Plain" sn="plain" ln2="(3 cups) confectioners sugar" qty="12-1/2" units="oz." />,
      <item ln1="Maple" sn="maple" ln2="pure maple syrup, more as needed" qty="1" units="cup" />,
      <item ln1="Lemon" sn="lemon" ln2="fresh lemon juice, more as needed" qty="6" units="Tbs." />
      );

      However, the data grid only has 3 columns, which display only @qty, @units, and @ln2.

      I need to deliver an array of arrays of those items only, as in:

      private var finalIngrtedientList:Array = new Array(
      ["12-1/2","oz.","(3 cups) confectioners sugar"],
      ["1","cup","pure maple syrup, more as needed"],
      ["6","Tbs.","fresh lemon juice, more as needed"]
      );

      What's the easiest way to accomplish this?'
        • 1. Re: Converting an XML Array to a multi-level array
          ntsiii Level 3
          You have an Array of XML nodes. That is quite odd. Why are you not using a normal dataProvider?

          Whatever, assuming you have a good reason, there is not an automatic way to do that. You will just need to loop over your nodes and build the array elements, and push them onto the array.

          Tracy
          • 2. Re: Converting an XML Array to a multi-level array
            Handycam Level 1
            I did that because most of the datagrids in the ap use XML data from an XML file.

            http://www.taunton.com/finecooking/cyor/muffins.aspx?ac=fp

            So the app has a series of drag n drop grids, the left "from" lists are loaded from XML file. Then I use the ArrayCollection of the destination list to populate other items in the app as process the recipe instructions. I need to keep the data "live", since the user can go back at any time and make changes that then need to ripple into the recipe.

            Occasionally, the client needs to add a few "hard-coded" items to this "chosen item" data set, so I create an Array in the same format as the existing XML data, so they can mix together seamlessly.

            I wish there was a better way, but this works so far.

            So what I am doing now is

            private function save():void {
            saveIngredients = [];
            var len:uint = _muffins.length;
            for (var i:int=0; i<len; i++){
            var a:Array = [];
            a.push(_muffins .@qty);
            a.push(_muffins
            .@units);
            a.push(_muffins .@ln2);
            ingredients1.push(a);
            }
            saveIngredients.push(ingredients1);
            }