Converting an XML Array to a multi-level array

Ask a Question related to Macromedia Flex General Discussion, Design and Development.

  1. #1

    Default Converting an XML Array to a multi-level array

    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?'

    Handycam Guest

  2. Similar Questions and Discussions

    1. New pure perl multi-level hash/array DBM
      Hey all, I have just completed a very unique DBM, written in pure perl, and submitted it to CPAN. It has true multi-level hash/array support...
    2. Multi-dimensioned sparse array ?
      Does anyone have an implementation of a multi-dimensioned sparse array? The only implementation that I can think of involves a mesh of...
    3. how to pass multi array as args
      Can someone show me how to pass multiple arrays argument? ie - .... mysub(@a, @b, @c); .... sub mysub { my @a = ? #arg1 an array $_ is...
    4. Multi-dimensional Array
      Hi, Array-Question: Suppose you have an array like: <? $invoices=$taxrate; $invoices=a number; ?>
    5. sorting multi-array
      hello, i have got a problem, tehere is an array: $x = array( array(15,55,array(1,2,3),3,5,array(1,2,5)),...
  3. #2

    Default Re: Converting an XML Array to a multi-level array

    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

    ntsiii Guest

  4. #3

    Default Re: Converting an XML Array to a multi-level array

    I did that because most of the datagrids in the ap use XML data from an XML
    file.

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

    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[i].@qty);
    a.push(_muffins[i].@units);
    a.push(_muffins[i].@ln2);
    ingredients1.push(a);
    }
    saveIngredients.push(ingredients1);
    }

    Handycam Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139