2 Replies Latest reply on Dec 3, 2015 1:36 AM by steverocket2

    Below script is works fine but i want to make the proper structured script...please change or suggest me.

    Jackkistens Level 1

      Dear All,

       

      Below script is works fine but i want to make the proper structured script...please change or suggest me.

       

      var myDoc = app.activeDocument;

      var myEveryName = new Array();

              var myEveryContent = new Array();

              var myEveryAttributes = new Array();

              var PrjAttr1= new Array();

              var PrjAttr2 = new Array();

              var PrjAttr3 = new Array();

      var myComment = myDoc.xmlElements[0].xmlComments[0].value;

      var xxx = myComment.substr(myComment.indexOf ("\" id",3));

      var projectTitle = myComment.replace(xxx,"").replace("<project title=\"","");

       

       

      =====================================

       

      var myfile = File("D:\\PC_TESTING\\"+projectTitle+"\\COVERS\\MergedInfoXML\\MergedInfo.xml");

       

      var myEveryName = new Array();

              var myEveryContent = new Array();

              var myEveryAttributes = new Array();

              var PrjAttr1= new Array();

              var PrjAttr2 = new Array();

              var PrjAttr3 = new Array();

              var myAttrValue = new Array();

              var myFinalAttrValue = new Array();

       

       

              var Simp = new Array();

             

       

              if(File(myfile).exists)

               {

                        myfile.open("r");

                        var Cont= myfile.read();

                        var roots = new XML(Cont);

                        traverse(roots);   

                         

                           for(var i=0; i<myEveryName.length; i++)

                           {

                                  if(myEveryName[i] == "info")

                                   {

                                          PrjAttr1.push(String(myEveryAttributes[i][0]));

                                          PrjAttr2.push(String(myEveryAttributes[i][1]));

                                          PrjAttr3.push(String(myEveryAttributes[i][2]));

       

                                       }

                                    if("simple" == myEveryName[i])

                                     {

                                          Simp.push(myEveryContent[i]);

                                         }

                               }

                   }

                else

                 {

                      alert("NOT Exist");

                       exit(0);

                     }

                

       

      mySqrtTag(myDoc); 

      function mySqrtTag(elm) 

          for (var i = 0; i < elm.xmlElements.length; i++) 

          { 

              if(elm.xmlElements[i].markupTag.name.toString() == "ce:intra-ref") 

              { 

                  for(var j = 0; j < elm.xmlElements[i].xmlAttributes.length; j++)

                  {

                      if(elm.xmlElements[i].xmlAttributes[j].name == "xlink:href")

                      {

                              var atValue = elm.xmlElements[i].xmlAttributes[j].value;

                             var xxx = atValue.replace("pii:Bpiinumber#","").replace (" ", " ")

                              for(var attValue = 0; attValue < PrjAttr3.length; attValue++)

                              {

                                  var finalValue = "pii:"+ PrjAttr1[attValue] + "#" + PrjAttr2[attValue];

                                 

                                  if((PrjAttr3[attValue].localeCompare (xxx) == 0))

                                  {

                                     

                                      var atValue = elm.xmlElements[i].xmlAttributes[j].value = String(finalValue);

                                     

                                     

                                      }

                                 

                                  }

                          }

                      }

              } 

              mySqrtTag(elm.xmlElements[i]);

          } 

      }

                             

      function traverse(tree)

               {

                 //   alert("Inside the traverse");

                   myEveryName.push(tree.name());

                   myEveryContent.push(tree.text());// you get the contents by using .text() insted of .name()

                   myEveryAttributes.push(tree.attributes());

                    if(tree.elements().length() > 0)

                       {

                           for(var iroots=0; iroots<tree.elements().length(); iroots++)

                               {

                                    traverse(tree.elements()[iroots]);

                                    }

                           }

                   }