Skip navigation
snegig
Currently Being Moderated

[JS] Delete empty tags InDesign cs4 Help Please

Jan 12, 2012 9:22 PM

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

 
Replies
  • Currently Being Moderated
    Jan 14, 2012 2:40 AM   in reply to snegig

    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

     
    |
    Mark as:
  • Currently Being Moderated
    Jan 17, 2012 9:21 PM   in reply to snegig

    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.

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points