I have an xml file that I need to loop though to find a specific node based on a String value. When it finds this node it also needs to know the index or depth of this node in the xml tree.
here is my xml.
Code:
<?xml version="1.0" encoding="UTF-8"?>
<menu>
<data>
<children>
<row id="0">
<title icon=""><![CDATA[Main Navigation 1]]></title>
<url></url>
<children>
<row id="0">
<title icon=""><![CDATA[Sub1 Menu1]]></title>
<url>/book</url>
</row>
<row id="1">
<title icon=""><![CDATA[Sub1 Menu 2]]></title>
<url>/grid</url>
</row>
</children>
</row>
<row id="1">
<title><![CDATA[Main Navigation 2]]></title>
<url>/book</url>
<children>
<row id="0">
<title><![CDATA[Sub2 Menu1]]></title>
<url>/guide1?page=0</url>
</row>
<row id="1" >
<title><![CDATA[Sub2 Menu2]]></title>
<url>/guide2?page=0</url>
</row>
</children>
</row>
</children>
</data>
</menu>
For example if I have the value of "/grid" I need to loop through my xml to find which node matches that value and keep a counter for which top level object it came form.
So right now I have 2 top level nodes called row 0 and row 1 If the search finds the value in row 0 then it needs to keep track of that value and so on.
Anyone know how I would achieve this.
I tried this which does find the node but it doesn't know which top level node its come from.
Actionscript Code:
var node:XML = data..row.( elements( "url" ) == fullPath )[0];
Then I tried a for loop but got stuck on how to deal with the search.
Actionscript Code:
var nod:XMLList = data.children.row;
var depth:int = 0;
for each (var item:XML in nod){
var current:XML = item;
/*if(current == node){
depth ++;
return;
}
*/
//nod = nod.children();
trace(current);
}