Recursively access xml nodes


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][INDENT]<title>Lesson 1: Variables</title>[/INDENT]


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



… 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]}



I came across a good tutorial on using a recursive function to access xml nodes by senocular here:

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

Any help or advice appreciated!