# XML to Arrays

**URL:** <https://forum.kirupa.com/t/xml-to-arrays/183845>\
**Category:** flash\
**Created:** [March 30, 2006, 5:32pm UTC](https://forum.kirupa.com/t/xml-to-arrays/183845 "2006-03-30T17:32:12Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![rgarimella](https://avatars.discourse-cdn.com/v4/letter/r/b5e925/32.png) [@rgarimella](https://forum.kirupa.com/u/rgarimella)\
**Post date:** [March 30, 2006, 5:32pm UTC](https://forum.kirupa.com/t/xml-to-arrays/183845/1 "2006-03-30T17:32:12Z")

</div>

Hi Folks

I have an [XML document shown below. I need to move the [URL=“http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q\_21795330.html#”]data into 1 [URL=“http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q\_21795330.html#”]array so that Top Node (Electronics) will have associated data of Child nodes (TV, [URL=“http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q\_21795330.html#”]Plasma](http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_21795330.html#), Digital Cam).

For eg like [[ [Electronics],[TV, Plasma, Digital]], [[Jewellery],[Beads, Pearls, Chains] ] ]

My objective is to have a list box for Top level nodes (Electronics, Jewellery) and then when you click on the Top level nodes another list box populates with Child nodes of the Selected node

Code attached below gets me the data into 2 different arrays. But I dont know how to associate the Top level node to that of the child node

var myXML = new [XML](http://www.experts-exchange.com/Web/WebDevSoftware/Flash/Q_21795330.html#)(); //new

var main\_menu\_array:Array = new Array();  
var submenu\_array:Array = new Array();

myXML.ignoreWhite = true;

myXML.onLoad = function(success) {  
if (success) {  
var l = this.childNodes.length // Get the Total number of Top Level Nodes  
for (var i=0; i\<l; i++){ // Loop thru the top level nodes  
t = this.childNodes\*.childNodes.length ; // Get the Child objects of the Top Level Nodes  
trace("top level\>\> " + this.childNodes\*.attributes.label); // Gets Electronics and Jewellery  
main\_menu\_array.push({Label:this.childNodes\*.attributes.label});

```
           for (var j=0; j&lt;t; j++){ // Loop thru the Child Objects submenu_array.push({Label:this.childNodes*.childNodes[j].attributes.label,Url:this.childNodes*.childNodes[j].attributes.url,Description:this.childNodes*.childNodes[j].attributes.description});
           }

      }
           main_menu_array.sortOn("Label");
           submenu_array.sortOn("Label", Array.CASEINSENSITIVE); // sort on result array on step_value

           mainMenu_listBox.setDataProvider(main_menu_array); // Add Top Level Items to the List Box
           mainMenu_listBox.setChangeHandler("setSizes");

```

} else {  
trace(“ERROR! XML not found.”);  
}  
};

myXML.load(“menu.xml”);

mainMenu\_listBox.setChangeHandler(“setSizes”);

function setSizes(component)  
{  
trace(“sizeArray”);  
sizeArray = mainMenu\_listBox.getSelectedItems();  
for (i = 0 ; i \< sizeArray.length ; i++)  
trace("Item " + (i + 1) + " = " + sizeArray\*.label);  
}

\<?xml version=“1.0” encoding=“iso-8859-1”?\>  
\<node label =“Electronics”\>  
\<node label=“TV” url=“app/elec.swf” isBranch = “true” description = “TV Description goes here”/\>  
\<node label=“Plasma” url=“app/plasma.swf” isBranch = “true” description = “PLASMA Description goes here”/\>  
\<node label=“Digital Cam” url=“app/digi.swf” isBranch = “true” description = “Digital Cam Description goes here”/\>  
\</node\>

\<node label =“Jewellery”\>  
\<node label=“Beads” url=“app/beads.swf” isBranch = “true” description = “Beads Description goes here”/\>  
\<node label=“Pearls” url=“app/pearls.swf” isBranch = “true” description = “Pearls Description goes here”/\>  
\<node label=“Chains” url=“app/chains.swf” isBranch = “true” description = “Chains Description goes here”/\>  
\</node\>

\<node label =“Audio”\>  
\<node label=“Speakers” url=“app/beads.swf” isBranch = “true” description = “Beads Description goes here”/\>  
\<node label=“Base” url=“app/pearls.swf” isBranch = “true” description = “Pearls Description goes here”/\>  
\<node label=“Controller” url=“app/chains.swf” isBranch = “true” description = “Chains Description goes here”/\>  
\</node\>

Thanks
