6 Replies Latest reply on Oct 29, 2013 2:47 AM by Liphou

    [JS] Write XML file

    Liphou Level 1
      Hello

       


      I read an XML file I y contribution of the change and I want to write it in a new XML file.


      I would get this presentation

      Capture d’écran 2013-10-28 à 18.56.32.png

      but I opt cesi

      Capture d’écran 2013-10-28 à 18.56.47.png


      Here is my code :

       

       

       

          leDossierOEBPS = "~/Desktop/content/";

       

          monEcritureContent(File (leDossierOEBPS + '/content.opf'),File (leDossierOEBPS + '/content5.opf'));

       

      function monEcritureContent(refFile,refFile2) {

         default xml namespace = 'http://www.idpf.org/2007/opf';

       

          var XMLHeader = '<\?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>';

          var XMLWorkbookHeader = "<\?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>";

          var XMLWorkbookHeader2 = " xmlns=\"http\://www.idpf.org/2007/opf\" unique-identifier=\"bookid\" version=\"2.0\"";

        

                 if(refFile != null) {

                              refFile.open("r");

                              var XMLToParse = refFile.read();

                              refFile.close();

                          

                              XMLToParse = XMLToParse.replace(XMLWorkbookHeader,"");

                              XMLToParse = XMLToParse.replace(XMLWorkbookHeader2,"");

                             

                         

                              var XMLData2 = new XML(XMLToParse);

                              XMLToParse = null;

                  } else {

                          alert("Error opening XML file.");

                  }

       

      refFile2.open("w");

      refFile2.encoding = "UTF8";

      refFile2.writeln (XMLHeader+XMLData2.toXMLString());

      refFile2.close();

       

      }//


      What is the correct control to write the XML tree?

       

      Thank you