4 Replies Latest reply: Jan 18, 2012 5:25 AM by snegig RSS

    [JS] Delete empty tags InDesign cs4 Help Please

    snegig

      Hi,

      Can anyone suggest me how i can delete empty tags in my InDesign cs4 files. Like this

       

      (1) <para></para>

      (2) <emphasis></emphasis>

       

      Both tags have no any matter between these tags. Any script you have please help me.

       

      Thank you so much adv.

       

      Regard

      snegig

        • 1. Re: [JS] Delete empty tags InDesign cs4 Help Please
          Green4ever Community Member

          Hi snegig, Try the below script and check.

           

          var xpath ="//*";
          var root  = app.activeDocument.xmlElements[0];
          var node  = null;
              try {
                  var proc  = app.xmlRuleProcessors.add([xpath]);
                  var match = proc.startProcessingRuleSet(root);
                  while(match!=undefined) {
                      node = match.element;
                      match = proc.findNextMatch();
                      content=node.contents;
                          if(node)
                              app.select(node);
                      var myText = app.selection[0];
                      var content=myText.contents;
                          if(content.search(/^[\s\r\n]+$/)!=-1){                                 
                              myText.untag();
                              }
                  }//End of While
              } //End of Try
              catch(ex){
                  alert(ex);
                  } 
              finally {
              proc.endProcessingRuleSet();
              proc.remove();
              }
          

           

          Thanks,

          Green4ever

          • 2. Re: [JS] Delete empty tags InDesign cs4 Help Please
            snegig Community Member

            Hi Green4ever,

             

            Thank you so much for answering. Script run OK but if these tags have no any data, blank space then script not work.

             

            thank you so much once again for help.

             

            Kudos to you.

            Regard

            snegig

            • 3. Re: [JS] Delete empty tags InDesign cs4 Help Please
              Green4ever Community Member

              Then that tag will not have only the space character inside that, some other character may also be inside. It will work for spaces also. You can test it with some input.

              • 4. Re: [JS] Delete empty tags InDesign cs4 Help Please
                snegig Community Member

                Hi Green4ever,

                 

                Thank you soooooooooo much.

                 

                Regard

                snegig