0 Replies Latest reply on Feb 11, 2017 5:48 AM by ahmadalattar

    how to read an created xml file localy ?

    ahmadalattar

      hello ,

       

      am having a problem read a local created xml file localy.

       

      reading code :

       

      function readConfig() {

      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {

        fs.root.getFile("cool.xml", {create: false}, function (f) {

        var file = f.fullPath;

        alert(file);

        var xhr = new XMLHttpRequest();

          xhr.addEventListener("load", function () {

              var parser = new DOMParser();

              var doc = parser.parseFromString(xhr.responseText, "application/xml");

              alert("Description : " +

                    doc.getElementsByTagName("Description").item(0).textContent);

          });

          xhr.open("get", file, true);

        xhr.responseType = 'blob';

          xhr.send();

         },alert("COOL NOT FOUND: " + fs.root.fullPath));

        },null);

         

      }

       

       

      writing code :

       

      function creatIt(){

      alert("file systeam request");

      window.requestFileSystem(LocalFileSystem.PERSISTENT, 0, function (fs) {

          console.log("file system open:" + fs.name);

        alert("boya");

          fs.root.getFile("cool.xml", { create: true, exclusive: false }, function (fileEntry) {

              console.log("fileEntry is file?" + fileEntry.name + fileEntry.isFile.toString());

              // fileEntry.name == 'someFile.txt'

              // fileEntry.fullPath == '/someFile.txt'

              writeFile(fileEntry, null);

      alert("file created :" + fileEntry.name);

          },

        null);

       

       

      },

      null);

        }

       

      writing code :

       

      function writeFile(fileEntry, dataObj) {

          // Create a FileWriter object for our FileEntry (log.txt).

          fileEntry.createWriter(function (fileWriter) {

       

       

              fileWriter.onwriteend = function() {

                  console.log("Successful file write...");

                  readFile(fileEntry);

              };

       

       

              fileWriter.onerror = function (e) {

                  console.log("Failed file write: " + e.toString());

              };

       

       

              // If data object is not passed in,

              // create a new Blob instead.

              if (!dataObj) {

                  dataObj = new Blob(['<Description>THIS IS JUST A TEST OF TESTS</Description>'], { type: 'application/xml' });

              }

       

       

              fileWriter.write(dataObj);

          });

      }

          function fail(error) {

              console.log(error.code);

          }

       

      any help please ??