# Searching XML, to arrays

**URL:** <https://forum.kirupa.com/t/searching-xml-to-arrays/163910>\
**Category:** flash\
**Created:** [September 27, 2005, 8:26am UTC](https://forum.kirupa.com/t/searching-xml-to-arrays/163910 "2005-09-27T08:26:30Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![coop](https://avatars.discourse-cdn.com/v4/letter/c/87869e/32.png) [@coop](https://forum.kirupa.com/u/coop)\
**Post date:** [September 27, 2005, 8:26am UTC](https://forum.kirupa.com/t/searching-xml-to-arrays/163910/1 "2005-09-27T08:26:30Z")

</div>

Hi all,

I’m trying to search through xml data and then load the inforamtion into seperate arrays. Below is the xml I’m searching and I want to collect it in red\_arr, blue\_arr and green\_arr

Code:  
portfolio\>  
\<red\>  
\<image\>red1\</image\>  
\<image\>red2\</image\>  
\<image\>red3\</image\>  
\<image\>red4\</image\>  
\<image\>red5\</image\>  
\</red\>  
\<blue\>  
\<image\>blue1\</image\>  
\<image\>blue2\</image\>  
\<image\>blue3\</image\>  
\</blue\>  
\<green\>  
\<image\>green1\</image\>  
\<image\>green2\</image\>  
\<image\>green3\</image\>  
\</green\>  
\</portfolio\>

Here is my Actionscript

ActionScript:  
my\_xml = new XML();  
my\_xml.ignoreWhite = true;  
my\_xml.onLoad = function(success) {  
if (success) {  
searchXML();  
} else {  
trace(“xml not loaded”);  
}  
};  
blue\_arr = new Array();  
red\_arr = new Array();  
green\_arr = new Array();  
my\_xml.load(“colors.xml”);  
function searchXML() {  
var start = my\_xml.firstChild.childNodes;  
for (var i = 0; i\<start.length; i++) {  
var allxml = start\*;  
if (allxml.nodeName == “blue”) {  
blue = allxml.childNodes;  
for (var n = 0; n\<blue.length; n++) {  
blue\_arr.push(blue[n].childNodes);  
trace(blue\_arr);  
//trace(blueValue);  
}  
}  
if (allxml.nodeName == “red”) {  
red = allxml.childNodes;  
for (var j = 0; j\<red.length; j++) {  
red\_arr.push(red[j].childNodes);  
trace(red\_arr);  
//trace(redValue);  
}  
}  
if (allxml.nodeName == “green”) {  
green = allxml.childNodes;  
for (var k = 0; k\<green.length; k++) {  
green\_arr.push(green[k].childNodes);  
trace(green\_arr);  
//trace(greenValue);  
}  
}  
}  
}

This works fine up to now, but the arrays are

Code:  
red1  
red1,red2  
red1,red2,red3  
red1,red2,red3,red4  
red1,red2,red3,red4,red5

and I just need

Code:  
red1,red2,red3,red4,red5

Also can anyone see a better way to do the actionscript, I dont know if its to repetitive, could I do this with two loops.
