  | |  | Recursion woes | Recursion woes
2004-02-21 - By Azinger, Richard
Back
Hello List,
I 'm trying to write a recursive function that make a smaller XML file from the full XML file to be used for a menu (tree component). The function seems to be losing it 's count(i).
Should I not be using a "for " loop with recursion? Or better yet, is there a better way?
Flash MX 2004 Pro
Windows 2000
Below is the function and the call to the function.
==========================================================
function getChildren(tempNode, nID, tStr) {
for(i=0;i <tempNode.childNodes.length;i++){
sNodeName = tempNode.childNodes[i].nodeName;
if(sNodeName == "LO " || sNodeName == "PAGE "){
iNodeID = tempNode.childNodes[i].attributes.ID;
nodeTitle = tempNode.childNodes[i].attributes.TITLE;
}
if(sNodeName == "PAGE "){
tStr=tStr+ " <PAGE pID= ' "+iNodeID+ " ' loID= ' "+nID+ " ' label= ' "+nodeTitle+ " ' / > ";
}else if(sNodeName == "LO "){
tStr=tStr+ " <LO loID= ' "+iNodeID+ " ' label= ' "+nodeTitle+ " ' > "+getChildren(tempNode.firstChild,iNodeID,tStr)+ " </LO > ";
}
}
return tStr;
}
menuStr = " <menu > "+getChildren(loNode,0, " ")+ " </menu > ";
menuXML = new XML(menuStr);
==========================================================
Below is loNode (with extra xml elements taken out)
==========================================================
<LEARNING_OBJECTS >
<LO ID= "54 " TITLE= "Chapter 1 " >
<PAGE ID= "256 " TITLE= "Chapter 1:Page 1 " AUDIO= "c256c1p1.mpg " >
<BODY1 >This is the body copy for chapter 1-page 1 </BODY1 >
</PAGE >
<PAGE ID= "257 " TITLE= "Chapter 1:Page 2 " AUDIO= "c256c1p2.mpg " >
<BODY1 >This is the body copy for chapter 1-page 2 </BODY1 >
</PAGE >
</LO >
<LO ID= "55 " TITLE= "Chapter 2 " >
<PAGE ID= "312 " TITLE= "Chapter 2:Page 1 " AUDIO= "c256c2p1.mpg " >
<BODY1 >This is the body copy for chapter 2-page 1 </BODY1 >
</PAGE >
<LO ID= "24 " TITLE= "Chapter 2 - Sub Chapter 1 " >
<PAGE ID= "150 " TITLE= "Chapter 2-sub chapter 1:Page 1 " AUDIO= "c150c2_2p1.mpg " >
<BODY1 >This is the body copy for chapter 2-sub chapter 1-page 1 </BODY1 >
</PAGE >
<PAGE ID= "151 " TITLE= "Chapter 2-sub chapter 1:Page 2 " AUDIO= "c150c2_2p2.mpg " >
<BODY1 >This is the body copy for chapter 2-sub chapter 1-page 2 </BODY1 >
</PAGE >
</LO >
<PAGE ID= "313 " TITLE= "Chapter 2:Page 2 " AUDIO= "c256c2p2.mpg " >
<BODY1 >This is the body copy for chapter 2-page 2 </BODY1 >
</PAGE >
<PAGE ID= "314 " TITLE= "Chapter 2:Page 3 " AUDIO= "c256c2p3.mpg " >
<BODY1 >This is the body copy(1) for chapter 2-page 3 </BODY1 >
</PAGE >
</LO >
</LEARNING_OBJECTS >
==========================================================
And this is what I want the output string to be
==========================================================
<menu >
<LO loID= "54 " label= "Chapter 1 " >
<PAGE pID= '256 ' loID= "54 " label= "Chapter 1:Page 1 " / >
<PAGE pID= "257 " loID= "54 " label= "Chapter 1:Page 2 " / >
</LO >
<LO loID= "55 " label= "Chapter 2 " >
<PAGE pID= "312 " loID= "55 " label= "Chapter 2:Page 1 " / >
<LO loID= "24 " label= "Chapter 2 - Sub Chapter 1 " >
<PAGE pID= "150 " loID= "24 " label= "Chapter 2-sub chapter 1:Page 1 " / >
<PAGE pID= "151 " loID= "24 " label= "Chapter 2-sub chapter 1:Page 2 " / >
</LO >
<PAGE pID= "313 " loID= "55 " label= "Chapter 2:Page 2 " / >
<PAGE pID= "314 " loID= "55 " label= "Chapter 2:Page 3 " / >
</LO >
</menu >
==========================================================
but this is all I get
========================================================== <menu >
<LO loID= '54 ' label= 'Chapter 1 ' >
<PAGE pID= '256 ' loID= '54 ' label= 'Chapter 1:Page 1 ' / >
<PAGE pID= '257 ' loID= '54 ' label= 'Chapter 1:Page 2 ' / >
</LO >
</menu >
==========================================================
Thanks for any help,
Rich Azinger
This communication is for use by the intended recipient and contains
information that may be privileged, confidential or copyrighted under
applicable law. If you are not the intended recipient, you are hereby
formally notified that any use, copying or distribution of this e-mail,
in whole or in part, is strictly prohibited. Please notify the sender
by return e-mail and delete this e-mail from your system. Unless
explicitly and conspicuously designated as "E-Contract Intended ",
this e-mail does not constitute a contract offer, a contract amendment,
or an acceptance of a contract offer. This e-mail does not constitute
a consent to the use of sender 's contact information for direct marketing
purposes or for transfers of data to third parties.
Francais Deutsch Italiano Espanol Portugues Japanese Chinese Korean
http://www.DuPont.com/corp/email_disclaimer.html
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Supported by Fig Leaf Software
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
Be sure to check the archives and the wiki:
http://chattyfig.figleaf.com/
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
http://chattyfig.figleaf.com/cgi-bin/ezmlm-cgi?1:mss:104899
=-- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- ---- --
To unsubscribe send a blank e-mail to:
Normal Mode: flashcoders-unsubscribe@(protected)
Digest Mode: flashcoders-digest-unsubscrive@(protected)
|
|
 |