2 Replies Latest reply on Jul 7, 2009 9:18 PM by Adobe-InDesign CS4

    [CS4-JS] - How to read the XML File / content value - reg.

    Adobe-InDesign CS4 Level 1

      Dear All


        I'm having one big doubt, regarding for reading the XML file Tag and Content to stored one variable....


      for example:





      <title>XML Reading </title>


















      How to read [each and every element and its value] the above xml file through JavaScript.


      For example I need the Tag <start_date> and its value to stored in one variable like...


      Tag_name = start_date;

      Tag_value = Today


      So, How to read the XML File using JavaScript [XML DOM] and stored each and every Tag content values....


      Please any one can give me a solutions, then I will be appriciate....


      Thanks & Regards

      T.R.Harihara SudhaN


        • 1. Re: [CS4-JS] - How to read the XML File / content value - reg.
          Thomas B. Nielsen Level 3



          First of all, your XML is full of errors, please post proper info, i like to help, but not editing typos.

          Have a look in the Javascript Tools Guide CS3 under XML


          var roots = new XML("<Roots><title>XML Reading</title><author_group><author><fname>Harihara</fname><sname>Sudhan</sname></author ><author><fname>Adobe</fname><sname>forums</sname></author></author_group><infos><date><st art_date>Today</start_date><end_date>Tomorrow</end_date></date></infos></Roots>");
          var myEveryName = new Array();




          function traverse(tree) {
              myEveryName.push(tree.name()); // you get the contents by using .text() insted of .name()
              if(tree.elements().length() > 0) {
                  for(var i=0; i<tree.elements().length(); i++) {

          • 2. Re: [CS4-JS] - How to read the XML File / content value - reg.
            Adobe-InDesign CS4 Level 1

            Dear Thomas


               Many thanks for the responce...and I'm really sorry to say for I made a mistake in the xml...


            Please here my original xml file



            <Profile_name> Els_pitStop</Profile_name>
            <!--       Blank Page Rule Set  -->
              <Ignore_master_page> true </Ignore_master_page>
              <Ignore_nonprinting_objects> true </Ignore_nonprinting_objects>
            <!--     End of the Blank Page Rule Set   -->







            ---------------------- ***** ----------------------------------

            I used the abobe xml to read each and every elemet using for REGEX operation.

            I used regex operation to read & match each and every element and get the content.


            For Example:


            var Fpath = File("D:\\Preflight\\Preflight.xml");
              if (Fpath.exists)
               var Cont= Fpath.read();
               //-------------------------------- Profile Name ---------------------------------------------//
               var Profile_name=/(<Profile_name>(.+?)<\/Profile_name>)/gi;
                var result = Profile_name.exec(Cont);
                var profileName = result[2]; //index 0, 1, gives full matching pattern


            //-------------------------------- Blank Pages  ---------------------------------------------//
                 var Ignore_master_page =/(<Ignore_master_page>(.+?)<\/Ignore_master_page>)/gi;
                  var result = Ignore_master_page.exec(Cont);
                  var ignore_master = result[2];
               var Ignore_nonprinting_objects =/(<Ignore_nonprinting_objects>(.+?)<\/Ignore_nonprinting_objects>)/gi;
                  var result = Ignore_nonprinting_objects.exec(Cont);
                  var ignore_nonprinting = result[2];

            //----------------------------------------- ****************************** ----------------------------------------------------//


            I used the above method is taken more than 10 min. Instead of the above method, please any one can help me to directly read the XML [XML DOM - used] to solve my problem.


            Because I tried your coding but its not working....


            Plaease kindly help me to solve the above XML -DOM reading problem through JAVA Script.



            Thanks & Regards

            T.R.Harihara SudhaN