Question
Going through entire XML structure
Hi guys,
I made the following function to recurse through an XML file:
private function parseMenuData(menuData:XML):void{
for each(var menuItem:XML in menuData.elements()){
trace("-----------------------------------------------------------");
trace("Menuitem " + menuItem.@name + "has " + menuItem.children().length() + " children.");
if(menuItem.children().length() > 0){
parseMenuData(menuItem);
}else{
trace("No children here");
}
}
}
No where I am getting stuck is how to store the structure. So if menuItem.children().length() > 0 then I know that node has children. If my structure was only one level, it'd be easy to go through the whole list and store it into an array. I am sure I can use a multi-dimensional array but not sure how to load it all in there since I don't know how many levels deep the XML file is I am loading....
Does that make sense? Any pointers? I'm not asking someone to write code for me but just make help point me in the right direction that I need to go for my own code...
Thanks!
I made the following function to recurse through an XML file:
private function parseMenuData(menuData:XML):void{
for each(var menuItem:XML in menuData.elements()){
trace("-----------------------------------------------------------");
trace("Menuitem " + menuItem.@name + "has " + menuItem.children().length() + " children.");
if(menuItem.children().length() > 0){
parseMenuData(menuItem);
}else{
trace("No children here");
}
}
}
No where I am getting stuck is how to store the structure. So if menuItem.children().length() > 0 then I know that node has children. If my structure was only one level, it'd be easy to go through the whole list and store it into an array. I am sure I can use a multi-dimensional array but not sure how to load it all in there since I don't know how many levels deep the XML file is I am loading....
Does that make sense? Any pointers? I'm not asking someone to write code for me but just make help point me in the right direction that I need to go for my own code...
Thanks!