How to recursively traverse an XML object in AS3

I found lots of examples on how to recusively parse through an XML object using E4X in ActionScript 3 (AS3). None of these examples were very simple or to the point. Most relied on the specifics of the XML instead of making general code that could access any XML object. E4X has eliminated much of the need to approach XML in this fashion, but there are still reasons to go through XML like this. Thus I am providing this simple example below which will print out the XML object:

You can use the parameter depth to indent the data if you want but that is not the point of this example. If you wanted to have a pretty string that represents the data you could use
The point of this function is to give you a skeleton to work with in its most simple form so then you can easily customize it to your purposes, whatever they may be. For example if you are populating a tree or directory ui from XML this would come in handy. If the article needs clairfication or has an error please leave a comment.

comments powered by Disqus