4 Replies Latest reply on Jun 11, 2010 11:04 AM by FlashGuruWiz

    Loading XML files into flex application


          Hi i'm new to flex and am trying to load a xml file that is currently located on my C drive in  "C:/Listener".  I'm having some issues on how to load it to my application.  Right now  i have this. (filename is equal to the name of my file.  In this case it is AuditTrail.XML)



      public function XMLload(filename:String):void { 

         var Data:XML = new XML();

         urlSource1 = "Listener/" + filename;    

         var xmlFileReq:URLRequest = new URLRequest(urlSource1);

         xmlLoader1 = new URLLoader(xmlFileReq);

         xmlLoader1.dataFormat = TEXTdataFormat;


        xmlLoader1.addEventListener(IOErrorEvent.IO_ERROR, xmlIOErrorHandler1);



         public function xmlLoadComplete1(event:Event):void {

         Data = XML(xmlLoader1.data);

         trace("loading xml list");


        xmlLoader1.removeEventListener(IOErrorEvent.IO_ERROR, xmlIOErrorHandler1);


      public function xmlIOErrorHandler1(event:IOErrorEvent):void {

         var errMsg:String = "xmlIOErrorHandler: " + event.toString();

         trace(errMsg + " file IO error ");


         xmlLoader1.removeEventListener(IOErrorEvent.IO_ERROR, xmlIOErrorHandler1);           



      This is what my xml file looks like i'm trying to load.


        <audit id="7011611">





          <employee>JEFF SANCHEZ</employee>




      I'm not getting an error so i dont know, maybe it is loading right but i'm just not reading it right.  I'm trying to display it in an advanceddatagrid. Setting the dataprovider to {Data.audit}. Is that right or should i be setting it to something else?  Any help would be appreciated.




        • 1. Re: Loading XML files into flex application
          David_F57 Level 5



          First with flex you can not programatically open a file outside the sandbox, for instance in a local testing if your project is in a folder called


          c:\myproject you can then request the xml  as "myxml.xml" if the xml was in


          c:\myproject\assets then the request path would be "assets/myxml.xml".


          if you were on a server and the file was either in the swf folder or below the swf path you could still use a relative reference. Otherwise you need the full url




          If you want the user to open an xml file then you can get it from the local harddrive using filereference which can open an OS based fileopen dialog box.




          • 2. Re: Loading XML files into flex application
            sensomage5 Level 1

            Is what i'm asking possible if i create an air application? or not.  Thanks for the insight!

            • 3. Re: Loading XML files into flex application
              David_F57 Level 5



              Air apps are different you can get access to the local file system programmatically. There are several examples on the web about the File class which is what you need to read up on.




              • 4. Re: Loading XML files into flex application
                FlashGuruWiz Level 1
                function XMLload(onComplete) {
                var request:URLRequest = new URLRequest("");
                .contentType = "text/xml";
                .data = "";
                .method = URLRequestMethod.POST;
                var loader:URLLoader = new URLLoader();
                .addEventListener(Event.COMPLETE ,function(e) { xmlParser(e); onComplete(e); } );
                return true;
                catch (e){
                return false;

                function xmlParser(e) {
                var xml:XML = new XML(URLLoader(e.target).data);