2 Replies Latest reply on Aug 28, 2012 2:00 PM by MMPGreg

    Load XML from applicationStorageDirectory

    invisibleBlade Level 1

      Hi all,

      I want my app to check the applicationStorageDirectory for an xml file and add an empty one if it is not there. Once this is done I want to load that xml file and work with in the app.

      I am trying to use the following method:

      private function getLocalQuizDirectoryXML():void
                          var localQuizDir:File = File.applicationStorageDirectory.resolvePath("quizDir.xml");
                               var fileStream:FileStream = new FileStream();
                               fileStream.open(localQuizDir, FileMode.WRITE);
                               fileStream.writeUTFBytes('<?xml version="1.0" encoding="UTF-8"?><directory></directory>');
                          var s:FileStream = new FileStream();
                          s.open(localQuizDir, FileMode.READ);
                          localXML = new XML(s.readUTFBytes(s.bytesAvailable));

      The first chunk works and the file is created if it does not exist and the xml is good. In the second chunk, if I trace s.readUTFBytes(s.bytesAvailable) I get the string I wrote in before but when I try to turn that to xml (as in the example) I get nothing. I have also tried using a Loader with the nativePath property in the URLRequest but that just throws an IOError.

      Does anyone know how I can load XML from applicationStorageDirectory in to my app so that it is an XML Object rather than a String?


      Thankyou kindly