Basic Recursion Problem

[SIZE=1][SIZE=2]I’m writing a xml search function using recursion and I’m having problems stopping it when it finds what it’s looking for. It parses the WHOLE tree even after it has found a node, which causes the function to return “undefined”. A hack would be to put it in a temp variable, assign it when it’s found and just let it run through the whole tree. Anythoughts?[/SIZE]

[SIZE=2][COLOR=Blue]function findNodeByName(theName, theXmlTree ){
[/COLOR][/SIZE][/SIZE][INDENT][SIZE=1][SIZE=2][COLOR=Blue] trace(“NODE >”+theXmlTree.attributes.name);[/COLOR][/SIZE][/SIZE]
[SIZE=1][SIZE=2][COLOR=Blue] if(theXmlTree.attributes.name == theName){[/COLOR][/SIZE][/SIZE][INDENT][SIZE=1][SIZE=2][COLOR=Blue] trace(“FOUND IT”);[/COLOR][/SIZE][/SIZE]
[SIZE=1][SIZE=2][COLOR=Blue] return (theXmlTree);[/COLOR][/SIZE][/SIZE]
[/INDENT][SIZE=1][SIZE=2][COLOR=Blue] }else{[/COLOR][/SIZE][/SIZE][INDENT][SIZE=1][SIZE=2][COLOR=Blue] if(theXmlTree.hasChildNodes() != false){[/COLOR][/SIZE][/SIZE][INDENT][SIZE=1][SIZE=2][COLOR=Blue] for(var i=0; i < theXmlTree.childNodes.length; i++){[/COLOR][/SIZE][/SIZE]
[INDENT][SIZE=1][SIZE=2][COLOR=Blue]findNodeByName(theName,theXmlTree.childNodes*);[/COLOR][/SIZE][/SIZE]
[/INDENT][SIZE=1][SIZE=2][COLOR=Blue] }[/COLOR][/SIZE][/SIZE]
[/INDENT][SIZE=1][SIZE=2][COLOR=Blue] }else{[/COLOR][/SIZE][/SIZE][INDENT][SIZE=1][SIZE=2][COLOR=Blue] trace(“leaf node”);[/COLOR][/SIZE][/SIZE]
[/INDENT][SIZE=1][SIZE=2][COLOR=Blue] }[/COLOR][/SIZE][/SIZE]
[/INDENT][SIZE=1][SIZE=2][COLOR=Blue] }[/COLOR][/SIZE][/SIZE]
[/INDENT][SIZE=1][SIZE=2][COLOR=Blue] }[/COLOR][/SIZE]
[/SIZE]