Writing to an XML File?

I simply want to add a element to an already existing element in an XML file through javascript. Here is my code:

    function WriteToXmlFile(){
	     var xmlDoc : XmlDocument = new XmlDocument();
	     xmlDoc.Load(Application.dataPath + "/data/saveWorld.xml");
	     elmRoot = xmlDoc.DocumentElement;
	     element = xmlDoc.CreateElement("block");
	     attribute = xmlDoc.CreateAttribute("ID");	
	     elmRoot.AppendChild(element);			//append "block" element to "blocks" element	

	     xmlDoc.Save(Application.dataPath + "/data/saveWorld.xml");


Like I said before I create an element called “block” then I want to make it a child of the root element (which btw is called “blocks”). Therefore the whole document should look like this:

alt text

But for some reason it doesn’t, instead the script makes it looks like this:

alt text

Why does this happen and how can I fix it to look like the first tree?


I dunno if this page will help you further?