Skip navigation
Currently Being Moderated

Removing empty XML tags & returns

Mar 26, 2012 8:08 PM

I have a XML feed from a web app (over which I have control as to how the XML is tagged etc) and the XML drops into an indd template, applies character, para, table and cell styles.


The issue I have is that if an XML tag is empty (and they often are), I can't search and replace for extra carriage returns as there's markers in there from the XML (I believe, correct me if I'm wrong).


If I select the invisible characters and paste them into the Find and Replace dialogue box, they show up as ~I (GREP) or ^I (normal), which is apparently an index marker.


Is there any way of getting rid of these via a script? If I try to search for those invisible characters, no changes get made, i.e. none are found.


Is there a GREP method that may work?


Thanks in advance.

  • Currently Being Moderated
    Mar 26, 2012 10:09 PM   in reply to Angusdog



    It is already discussed few months ago.See the thread, Any way I'm reposting it. Use the below script,



    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();
                var myText = app.selection[0];
                var content=myText.contents;
            }//End of While
        } //End of Try
        finally {




    Mark as:
  • Currently Being Moderated
    Mar 27, 2012 9:17 PM   in reply to Angusdog

    You can use the script as is. The variable xpath holds a xpath expression. "//*"  will match any tag in any location. To know more about xpath see and you can see some examples here: Remember that this is not a recomendation, it is just for reference only.




    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