2 Replies Latest reply on Oct 25, 2013 1:57 AM by Liphou

    [JS] XML transformation

    Liphou Level 1

      Hello,

      I want handling a xml file with ESTK but I is not the beginning of a solution.

      I am the

       

      myXMLFile = File ("~/Desktop/content/content.opf");

      myXMLFile.open ('r');

      myXMLFile.encoding = "UTF-8";

      currentXML var = new XML (myXMLFile.read ());

      myXMLFile.close ();

      $ writeln (currentXML.toXMLString ()).;

       



      Can anyone give me some stuff?


      thank you

       

       

      Bonjour,

       

      je voudrais manipulé un fichier xml avec ESTK mais je en trouve pas le début d'une solution.

       

      J'en suis là;

      myXMLFile = File ("~/Desktop/content/content.opf");

      myXMLFile.open ('r');

      myXMLFile.encoding = "UTF-8";

      currentXML var = new XML (myXMLFile.read ());

      myXMLFile.close ();

      $ writeln (currentXML.toXMLString ()).;

       

      Quelqu'un peut-il me donner un quelque truc?

      Merci

        • 1. Re: [JS] XML transformation
          Gonterman1201 Level 1

          This is how I read a xml file.

           

          var myXML_Hot="/Volumes/This is a link to your folder/"+myString+"-000-14.xml";

          xmlPath = File(myXML_Hot);

          if (xmlPath.open('r')) {

          xmlText = xmlPath.read();

          xmlPath.close();

          x = XML(xmlText);

          s = x.CUSTOMERID.toString(); /// the name after x is the tag

          csa = x.CSRNAME.toString();

          mySchoolName.text=s;

          }

          • 2. Re: [JS] XML transformation
            Liphou Level 1

            Thank you, I found what helps me, here is the code, I do not know if this is the best codes.
            But I find it hard to test if a tag exite.

            myXMLFile =  File("~/Desktop/content/content.opf");
              myXMLFile.open('r');
              myXMLFile.encoding = "UTF-8";
              var currentXML = new XML(myXMLFile.read());
              //maLectureContent(myXMLFile);
             
              $.writeln (maLectureContent(myXMLFile));

            function maLectureContent(XMLFile) {
              default xml namespace = "xmlns\:dc=\"http\://purl.org/dc/elements/1.1/\"";
              var refFile = XMLFile;
              var XMLHeader = '';
              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();
              var XMLsettings = XML.settings;
              XMLsettings.prettyPrinting = false;
              XML.setSettings(XMLsettings);
             
              XMLToParse = XMLToParse.replace(XMLWorkbookHeader,"");
              XMLToParse = XMLToParse.replace(XMLWorkbookHeader2,"");
             
              $.write (XMLToParse);
              var XMLData = new XML(XMLToParse);
              XMLToParse = null;
              } else {
              alert("Error opening XML file.");
              }


              var test = {title:((XMLData.metadata['dc:title'].length() != 0)? XMLData.metadata['dc:title']:"vide"),
              desscription:((XMLData.metadata['dc:description'].length() != 0)? XMLData.metadata['dc:description']:"vide"),
              rights:((XMLData.metadata['dc:rights'].length() != 0)? XMLData.metadata['dc:rights']:"vide"),
              creator:((XMLData.metadata['dc:creator'].length() != 0)? XMLData.metadata['dc:creator']:"vide"),
              language:((XMLData.metadata['dc:language'].length() != 0)? XMLData.metadata['dc:language']:"vide"),
              date:((XMLData.metadata['dc:date'].length() != 0)? XMLData.metadata['dc:date']:"vide"),
              publisher:((XMLData.metadata['dc:publisher'].length() != 0)? XMLData.metadata['dc:publisher']:"vide"),
              subject:((XMLData.metadata['dc:subject'].length() != 0)? XMLData.metadata['dc:subject']:"vide"),
              language:((XMLData.metadata['dc:language'].length() != 0)? XMLData.metadata['dc:language']:"vide"),
            identifier:((XMLData.metadata['dc:identifier'].length() != 0)? XMLData.metadata['dc:identifier']:"vide")};

            //var test = XMLData.spine.itemref[2].@idref;
            return (test["date"]);

            }