# How to write an XML file?

**URL:** <https://forum.kirupa.com/t/how-to-write-an-xml-file/164097>\
**Category:** flash\
**Created:** [September 28, 2005, 3:09pm UTC](https://forum.kirupa.com/t/how-to-write-an-xml-file/164097 "2005-09-28T15:09:54Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![awholeuniverse](https://avatars.discourse-cdn.com/v4/letter/a/0ea827/32.png) [@awholeuniverse](https://forum.kirupa.com/u/awholeuniverse)\
**Post date:** [September 28, 2005, 3:09pm UTC](https://forum.kirupa.com/t/how-to-write-an-xml-file/164097/1 "2005-09-28T15:09:54Z")

</div>

I am a newbie to actionscript and I was hoping someone might help with this.  
I am trying to load an xml file into my movie and then when a button is pressed write the xml file.

Here’s the code (I’ve put this code on a new layer, first frame):  
xmlData = new XML();  
xmlData.ignoreWhite = true;  
xmlData.onLoad = function(success) {  
if (success) {  
trace('data.xml loaded. Contents are: '+this.toString());  
}  
};  
xmlData.load(“data.xml”);

The code for the button :

on(press){  
var event = 1;  
trace(event);  
var element:XMLNode = xmlData.createElement(“element1”);  
xmlData.appendChild(element);  
trace(xmlData);  
}  
Practically what I want is that the value of the variable event gets written in the XML file.  
Can someone help me?

Thank you!
