Recursively access xml nodes

hi,

I’m very new to actionscript 3.

I’m trying to figure out how to use a recursive function to access an xml file which is basically a hierarchical menu as follows:

<course>[INDENT]<section>[/INDENT][INDENT][INDENT]<title>Introduction to Actionscript</title>[/INDENT]

[INDENT]<section>[/INDENT]

[INDENT][INDENT]<title>Lesson 1: Variables</title>[/INDENT]

[INDENT]<section>[/INDENT]

[INDENT][INDENT]<title>Topic 1: Data types</title>[/INDENT][/INDENT][INDENT]</section>[/INDENT]</section>

[/INDENT]</section>

[/INDENT]</course>

… basically I want this menu to adapt to different scenarios, so that there can be (theoretically) an unlimited number of sections nested within other sections.

my ‘pseudocode’ goes something like this (I’ve tried it a few ways in as3, but no luck)

 
 

parseStructure(courseNode){[INDENT]for each(section in courseNode){[INDENT]trace(title);[/INDENT][INDENT]if (section has sections){[INDENT]parseStructure(section);[/INDENT]}
 

[/INDENT]}
 

[/INDENT]}

I came across a good tutorial on using a recursive function to access xml nodes by senocular here: http://www.kirupa.com/web/xml/examples/mx04ASclasses.htm

…but I am having trouble applying the theory behind this to get it working in actionscript 3.

Any help or advice appreciated!

Thanks!
Karen