2 Replies Latest reply on Dec 11, 2010 4:37 AM by Mac_06

    Untag empty xml tag JS[CS4]

    Mac_06 Level 2

      I think this the right place to ask this.............

      I've seen something like same but it doesn't work for me. I have a table which is created using xml rules, some time it contains empty xml tag also converted into row but I don't want these empty rows. After table creation empty rows need to be deleted.

      I've got this script from this forum which delete empty rows

       

       

      for(var i=myDocument.textFrames.length-1; i>=0; i--){
       
        for(var j=myDocument.textFrames[i].tables.length-1; j>=0; j--){
       
         for(var k=myDocument.textFrames[i].tables[j].rows.length-1; k>=0; k--){
       
          myContents = 0;
          for(var l=myDocument.textFrames[i].tables[j].rows[k].cells.length-1; l>=0; l--){
       
           if (myDocument.textFrames[i].tables[j].rows[k].cells[l].contents != "") myContents++;
       
           }
           if (myContents == 0) myDocument.textFrames[i].tables[j].rows[k].remove();
       
         }
       
        }
      }
      

       

       

      but incase of any cell contains empty xml element it goes blank. Could any one help on this.

       

      Thanks

      Mac

        • 1. Re: Untag empty xml tag JS[CS4]
          Mi_D Level 3

          try below code

           

          var xpath ="//Story/Table/Cell/child::* ";

                           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==false){                                 
                           myText.untag();
                           }
                          }
                         } catch( ex ) {
                          alert(ex);
                         } finally {
                          proc.endProcessingRuleSet();
                          proc.remove();
                          }

           

          MI_D

          • 2. Re: Untag empty xml tag JS[CS4]
            Mac_06 Level 2

            Many Thanks

             

            It is working fine

             

            Mac