# Reading and writing xml

**URL:** <https://forum.kirupa.com/t/reading-and-writing-xml/287847>\
**Category:** flash\
**Created:** [May 6, 2009, 11:36pm UTC](https://forum.kirupa.com/t/reading-and-writing-xml/287847 "2009-05-06T23:36:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jkirkerx](https://avatars.discourse-cdn.com/v4/letter/j/ecb155/32.png) [@jkirkerx](https://forum.kirupa.com/u/jkirkerx)\
**Post date:** [May 6, 2009, 11:36pm UTC](https://forum.kirupa.com/t/reading-and-writing-xml/287847/1 "2009-05-06T23:36:08Z")

</div>

I’ve been searching all morning for some samples on how to read and write xml files.  
Here’s what I have so far.

My XML File called Call2Action.xml  
\<?xml version=“1.0” encoding=“utf-8”?\>  
\<Call2Action version=“1.0” creationDate=“2009-05-06”\>  
\<ProceraFixedImplantBridge\>  
\<Yes\>5\</Yes\>  
\<No\>2\</No\>  
\</ProceraFixedImplantBridge\>  
\<RetainingFunctionality\>  
\<Yes\>2\</Yes\>  
\<No\>7\</No\>  
\</RetainingFunctionality\>  
\</Call2Action\>

```auto
import flash.events.*;
import flash.xml.*;
import flash.net.URLLoader;
import flash.net.URLRequest;

var xmlLoader:URLLoader = new URLLoader();
xmlLoader.load(new URLRequest("XML/Call2Action.xml"));
xmlLoader.addEventListener(Event.COMPLETE , loadXML);
var xmlData:XML = new XML();
var idx:int = 0;

function loadXML(e:Event):void {
    xmlData = new XML(e.target.data);
    trace("====>" + xmlData);
    for each (var idx:XML in xmlData) {
        trace("====>Yes=" + String(xmlData[idx].Yes));
        trace("====>No=" + String(xmlData[idx].No));
        
    }
}

```

‘String(xmlData[idx]. **Yes** ’ is where I’m having a problem, can’t figure out the syntax for declaring the element I want to read, plus I want to read the elements inside let’s say \<ProceraFixedImplantBridge\>. I need to add that to the code.

I want to increment the counter for yes or no, and write the file back.

Any help appreciated - AS3
