hi everyboby, i have a problem creating a dynamic mutlidimensional array and i would appreciate some help. this is the case. i load an xml file of unknown depth. i “read” it with the help of a recursive function. i have declared a results_arr which is the array that will hold the xml data, both attributes like results_arr[xml.name().toString()] = xml.attribute(); and text if there is any on each final xml node. the problem is i am having a problem applying it to the code. here is the code for parsing the xml data :
private var xml:XML;
private var results_array:Array; /// array to hold data
public function sec_xml(xml:XML) {
this.xml=xml;
var intial_attr_len:int=xml.attributes().length()-1;
results_array=[];
if (intial_attr_len>=0) {
for (var i:int=0; i<=intial_attr_len; i++) {
results_array[xml.attributes()*.name().toString()]=xml.attributes()*;
//trace("initial attribute "+results_array[xml.attributes()*.name().toString()]);
}
}
for each (var xml_l:XML in xml.elements()) {
results_array[results_array.length]=[temp_arr];
dig_deeper(xml_l,temp_arr);
}
}
private function dig_deeper(xml:XML,arr:Array=null):void {
/// reads attributes if there are any
for each (var att:XML in xml.attributes()) {
trace("attribute "+att.name()+" = "+att);
}
/// final xml instance reads any text if there is any
if (xml.children()==xml) {
trace("final "+xml.name()+" = "+xml);
}
else {
/// reads next xml instance
for each (var new_xml:XML in xml.elements()) {
dig_deeper(new_xml,arr);
}
}
}
can someone help me to constract the dynamic multidimensional array describing tha loaded xml document ?