3 Replies Latest reply on Mar 27, 2012 9:17 PM by Green4ever

    Removing empty XML tags & returns

    Angusdog Level 1

      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.

        • 1. Re: Removing empty XML tags & returns
          Green4ever Level 3



          It is already discussed few months ago.See the thread http://forums.adobe.com/message/4139703#4139703, 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 {




          • 2. Re: Removing empty XML tags & returns
            Angusdog Level 1

            Thanks very much for that. I did search this forum and not sure why I didn't see that earlier post.


            The variable xpath - what does that refer to, i.e. what should I set that to? Is that the path to the XML file, or the active document?


            Sorry for the newb questions - this is somewhat of new territory for me.




            • 3. Re: Removing empty XML tags & returns
              Green4ever Level 3

              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 http://www.w3.org/TR/xpath/#section-Introduction and you can see some examples here: http://www.adp-gmbh.ch/xml/xpath.html. Remember that this is not a recomendation, it is just for reference only.




              1 person found this helpful