This is an archived tutorial from the kirupa.com legacy collection. It covers software that may no longer be available, but it is kept online because the ideas still hold up.
In the squirrel finder and file listing examples, the XML loaded was only accessed one time, at the point directly after loading was complete. After that, anything dealing with the XML instance directly was, well, nonexistent. The information needed was immediately extracted and the XML instance was thereafter abandoned.
When dealing with loaded XML, this is, I think, the general approach (that should be) taken using XML in Flash. First obtain (load) the XML, then get what you need from it, converting its content into whatever internal Flash representation you need it to be in and then forget about it. In the squirrel finder, this representation was that of a list of buttons and a few variables which get used to display a text field; none of which screams "I'm XML!" In doing this, you're simplifying the process of dealing with the complications of XML as you only have to deal with it once.
Now this ideology changes a little bit when you need to take loaded XML and send it back out of Flash as XML. If you need that XML to change while in Flash, you will want to continuously work from the XML instance to assure its contents reflect what is seen in Flash.
When it comes to editing XML, if there's one thing to be wary of, it's the childNodes array. It seems simple enough but it can cause a whole lot of confusion when you are trying to manage and alter your XML data. The reason is because a childNodes array is not the actual construct of the internal workings of an XML object used to hold XML nodes. It is merely a representation. It contains valid node references but altering a childNodes array will not effect the the XML from which it came. For example, putting:
node.childNodes[0] = node.childNodes[1];
will do absolutely nothing despite your thoughts that you may have just copied the contents of childNodes[1] into childNodes[0]. Why is this so you ask? It has to do with what the childNodes property really is.
As you know, the childNodes property for any given XMLNode instance (from within an XML instance) provides you with an array of the nodes contained within that node. However, this array is a copy - a copy of whatever internal array or structure is used to truly represent the list of children within any element. So rather than thinking of childNodes as a direct property of an element, think of it more as an instruction or a function call that returns a new array with XMLNode references of that element's children. Because of this any change to an XML array will not be reflected in the actual XML. A loose internal representation of what the childNodes property does as a function may look like this:
function childNodes(){
var children = new Array();
for (child_elements in this_element) {
children.push( this_element[child_element] );
}
return children;
}
As a function, childNodes here creates a new array and adds child elements of the current element into the array one by one for each contained within. That array is then returned and given to the childNodes property.
Now, that having been said, it's important to understand that each XMLNode within a childNodes array is directly related to the XML. So adding a or changing an attribute within an element of a child nodes array will actually change the internal XML itself since you're dealing with the real XML node. It's just when you're talking about the array elements directly, their order and their direct (non referential) values. For instance, sorting an array assigned to equal a childNodes array will sort the array but have no affect on the order of the elements within the XML as the following diagram shows.

[ sorting a childnodes array wont affect the xml ]
Though the array itself has rearranged its order, the organization of the actual XML remains unchanged. This actually can be a good thing since sorting an array is a lot easier than sorting XML. If you are keeping a sortable list of XML data, using an array to order that data is a lot easier than sorting the XML nodes individually. The Array object in Flash provides a sort function to ease this process. No such method exists for XML.
That wraps up this tutorial. A huge thank you to all of you who buy kirupa's books, became a paid subscriber, watch the videos, and/or interact on the forums. Your support is what keeps writing like this online! 😇
This tutorial was written by senocular, also known as Trevor McCauley. He has been one of this community's most generous teachers since the early Flash days, and he is still around: find him on senocular.com and on the forums.
:: Copyright KIRUPA 2026 //--