XML confusion: cycling through children

Hi, I am rather new to Flash and XML…

I have an XML file that looks something like this:


<?xml version="1.0" encoding="iso-8859-1"?>
<calc-growth>

<state name="california">
	<location city="san_francisco">
		<telephone>(555) 123-4567</telephone>
		<telephone2>(555) 123-456203456</telephone2>
		<fax>(555) 123-4569</fax>
		<address1>1 Main St.</address1>
		<address2>nothing</address2>
		<email>cali email</email>
	</location>
</state>

<state name="colorado">
	<location city="fort_collins">
		<telephone>(555) 123-4567</telephone>
		<telephone2>(555) 123-4568</telephone2>
		<fax>(555) 123-4569</fax>
		<address1>1 Main St.</address1>
		<address2></address2>
		<email></email>
	</location>
	
	<location city="boulder">
		<telephone>(555) 123-4567</telephone>
		<telephone2>(555) 123-4568</telephone2>
		<fax>(555) 123-4569</fax>
		<address1>1 Main St.</address1>
		<address2></address2>
		<email></email>
	</location>
	
	<location city="denver">
		<telephone>(555) 123-4567</telephone>
		<telephone2>(555) 123-4569</telephone2>
		<fax>(555) 123-4569</fax>
		<address1>1 Main St.</address1>
		<address2></address2>
		<email></email>
	</location>
</state>

<state name="connecticut">
	<location city="hartford">
		<telephone>(555) 123-4567</telephone>
		<telephone2>(555) 123-4568</telephone2>
		<fax>(555) 123-4569</fax>
		<address1>1 Main St.</address1>
		<address2></address2>
		<email></email>
	</location>
</state>

I have already been able to make an array based off of the names of the states:


xml.onLoad = function(ok) {
	avAll = this.firstChild.childNodes;
	avStates = new Array();
	for (var i = 0; i<avAll.length; i++) {
		avStates.push(avAll*.attributes.name);
	}
}

BUT, what I would like to do is create a multi-dimensional array with the state name and it’s cities.

So the array should be formatted like this:


trace(avStates[0][0]); //returns san_francisco
trace(avStates[1][0]); //returns fort_collins
trace(avStates[1][0]); //returns boulder
trace(avStates[1].length); //returns 3

Im sure its possible but Ive been trying and trying for hours to no avail. :m: I dont know if I maybe formatted the XML file wrong for this type of thing?

HELP PLEASE!! :slight_smile: