Dynamically add XML element for each item on stage

Hey,
I am writing a program where the user can, in the simplest terms, drag and drop things on to the stage. I need the user to be able to save what they have done and when they come back choose to reload their previous project. My plan was to write all the information(object class, x and y values etc) to an xml file and when the user chooses to load a particular project, rebuild the stage with all objects in their correct locations. My problem is, how do you add an xml element with all of its attributes and child elements dynamically for each object added to the stage?

I’m pretty new to XML, and sort of new to actionscript but I figured this would work:

[LEFT][COLOR=#993300]var[/COLOR] test:[COLOR=#993300]XML[/COLOR] = <test/>; 
test.[COLOR=#000000]title[/COLOR] = [COLOR=#0000FF]"Test XML"[/COLOR]; 

  [COLOR=#993300]for[/COLOR] [COLOR=#000000]([/COLOR][COLOR=#993300]var[/COLOR] i=[COLOR=#000000]0[/COLOR]; i<platform.[COLOR=#000000]numChildren[/COLOR]; i++[COLOR=#000000])[/COLOR] [COLOR=#000000]{[/COLOR]     [COLOR=#993300]
    var[/COLOR] instance = platform.[COLOR=#000000]getChildAt[/COLOR][COLOR=#000000]([/COLOR]i[COLOR=#000000])[/COLOR]; 
   
 test.[COLOR=#000000]stageObject[/COLOR] = <stageObject/>; 
    test.[COLOR=#000000]stageObject[/COLOR].@[COLOR=#993300]name[/COLOR] = instance.[COLOR=#993300]name[/COLOR];     
    test.[COLOR=#000000]stageObject[/COLOR].[COLOR=#000000]objType[/COLOR] =  getDefinitionByName[COLOR=#000000]([/COLOR]getQualifiedClassName[COLOR=#000000]([/COLOR]instance[COLOR=#000000])[/COLOR][COLOR=#000000])[/COLOR];         
    test.[COLOR=#000000]stageObject[/COLOR].[COLOR=#000000]objX[/COLOR] = instance.[COLOR=#000000]x[/COLOR];     
    test.[COLOR=#000000]stageObject[/COLOR].[COLOR=#000000]objY[/COLOR] = instance.[COLOR=#000000]y[/COLOR];     
    test.[COLOR=#000000]stageObject[/COLOR].[COLOR=#000000]objRot[/COLOR]  = instance.[COLOR=#000000]rotation[/COLOR];     
    test.[COLOR=#000000]stageObject[/COLOR].[COLOR=#000000]objScaleY[/COLOR] = instance.[COLOR=#000000]scaleY[/COLOR]; 
[COLOR=#000000]}[/COLOR] 

 [COLOR=#993300]trace[/COLOR] [COLOR=#000000]([/COLOR]test[COLOR=#000000])[/COLOR];
 
[/LEFT]

Needless to say, it didn’t. It only adds the information for the most recently added object.

I’ve tried

    
[LEFT]test.[COLOR=#993300]appendChild[/COLOR][COLOR=#000000]([/COLOR]<stageObject/>[COLOR=#000000])[/COLOR][/LEFT]

[LEFT]
[/LEFT]

for each added object and I’ve tried

[LEFT]

test.[COLOR=#000000]insertChildAfter[/COLOR][COLOR=#000000]([/COLOR]test.[COLOR=#000000]stageObject[/COLOR], </stageObject>[COLOR=#000000])[/COLOR]

[/LEFT]

in a for loop as well. But, these give me a warning that says “adding an element with more than one item is not supported” or something like that.

Any help with this would be greatly appreciated… Or if anyone has a better idea on how I could accomplish the saving and reloading task, I’m open to hear it. Thanks in advance.