6 Replies Latest reply on Aug 18, 2016 7:33 AM by sreekarthik.k@gmail.com

    Move more then one xml element to particular script labeled textframe

    Level 1

      #include "glue code.jsx";

      var myDoc = app.activeDocument;

      var myLabel = "received";// change to label

      var myPage = app.properties.activeWindow && app.activeWindow.activePage;

      var myTextFrames = app.activeDocument.textFrames.everyItem().getElements().slice(0);

      l = myTextFrames.length,

      //____________________ XML RULE SET

      var myRuleSet = new Array (new Move_element); 

      with(myDoc){

          var elements = xmlElements;

          __processRuleSet(elements.item(0), myRuleSet);

      }

       

       

      function Move_element(){

          this.name = "r";

          this.xpath = "//a";

          this.apply = function(myElement, myRuleProcessor){

              with(myElement){

                 // app.select(myElement);

            //     try{

              while (l--)

              {

                  if (myTextFrames[l].label != myLabel) continue;

                     myElement.placeXML(myTextFrames[l])

                  //   break;

                  myTextframes[l].fit(FitOptions.FRAME_TO_CONTENT);

             }

            

                     // }catch(e){}

                  }

              return true;

              }

          }

       

       

       

       

      I need to move more than one xml element particular script labeled text frame but At a time I can only move one element.

       

       

      Also while move the element script throws the below error message.

      Error1.PNG

       

       

       

      Its removing the next paragraph paragraph style. How to fix thix issue.

       

       

      Error2.PNG

        • 1. Re: Move more then one xml element to particular script labeled textframe
          Level 1

          How Places XML content into the story, without replacing the existing content.


          • 2. Re: Move more then one xml element to particular script labeled textframe
            karthiks94217840 Level 2

            HI sreekarthik,

             

            You have completed in the above coding script?

             

            Please replay my post: "How can we Move the Contents of an xml element into text frame label in inDesign Script"

             

            Very urgent friend,

             

            Thanks in Advance

            KS

            • 3. Re: Move more then one xml element to particular script labeled textframe
              Level 1

              try this

               

              var myLabel = "a";// change to label 

               

               

               

               

              //____________________ XML RULE SET 

              myRuleSet = new Array (new Move_element);  

               

               

               

               

              with(myDoc){ 

                  var elements = xmlElements; 

                  __processRuleSet(elements.item(0), myRuleSet); 

               

               

                 

               

               

               

               

               

               

               

               

              function Move_element(){ 

                  this.name = "r"; 

                  this.xpath = "//a"; 

                  this.apply = function(myElement, myRuleProcessor){ 

                      with(myElement){ 

               

               

                      while (l--)

                      { 

                          if (myTextFrames[l].label != myLabel) continue; 

                             myElement.placeXML(myTextFrames[l])

                          break;

                     } 

               

               

                          } 

                      return true; 

                      } 

                  } 

              • 4. Re: Move more then one xml element to particular script labeled textframe
                karthiks94217840 Level 2

                Hi Karthik,

                 

                Thanks to share this code,

                 

                Still, I have received error report. Please see below screenshot for your reference only.

                 

                1Untitled.png

                 

                Please help friend. very urgent

                 

                Thanks

                KS

                • 5. Re: Move more then one xml element to particular script labeled textframe
                  karthiks94217840 Level 2

                  Here with, i have using "window >> CS6 >> version - 8.0"

                   

                  Error in Application:

                   

                  2Untitled.png

                   

                  Thanks

                  Ks

                  • 6. Re: Move more then one xml element to particular script labeled textframe
                    Level 1

                    Copy the code below

                     

                     

                     

                     

                     

                    //////////////////////

                     

                     

                     

                     

                    //========================================================================================

                    //

                    //  $File: //depot/indesign_5.0/gm/build/scripts/xml rules/glue code.jsx $

                    //

                    //  Owner: Lin Xia

                    //

                    //  $Author: sstudley $

                    //

                    //  $DateTime: 2007/02/15 13:37:33 $

                    //

                    //  $Revision: #1 $

                    //

                    //  $Change: 505969 $

                    //

                    //  Copyright 2006 Adobe Systems Incorporated. All rights reserved.

                    // 

                    //  NOTICE:  Adobe permits you to use, modify, and distribute this file in accordance

                    //  with the terms of the Adobe license agreement accompanying it.  If you have received

                    //  this file from a source other than Adobe, then your use, modification, or

                    //  distribution of it requires the prior written permission of Adobe.

                    //

                    //  DESCRIPTION: JavaScript glue code for XML Rules Processing

                    //

                    //========================================================================================

                     

                     

                    //app.scriptPreferences.version = 6.0;

                     

                     

                     

                     

                    function ruleProcessorObject(ruleSet, ruleProcessor) {

                       this.ruleSet = ruleSet;

                       this.ruleProcessor = ruleProcessor;

                    }

                     

                     

                     

                     

                    function __makeRuleProcessor(ruleSet, prefixMappingTable){

                      // Get the condition paths of all the rules.

                      var pathArray = new Array();

                      for (i=0; i<ruleSet.length; i++)

                      {

                      pathArray.push(ruleSet[i].xpath);

                      }

                     

                     

                        // the following call can throw an exception, in which case

                        // no rules are processed 

                        try{

                         var ruleProcessor = app.xmlRuleProcessors.add(pathArray, prefixMappingTable);

                        }

                        catch(e){

                        throw e;

                        }

                        var rProcessor =  new ruleProcessorObject(ruleSet, ruleProcessor);

                      return rProcessor;

                    }

                     

                     

                    function __deleteRuleProcessor(rProcessor) {

                      // remove the XMLRuleProcessor object

                      rProcessor.ruleProcessor.remove();

                     

                      // delete the object properties

                      delete rProcessor.ruleProcessor;

                      delete rProcessor.ruleSet;

                     

                      // delete the object itself

                      delete rProcessor;

                    }

                     

                     

                    function __processRuleSet (root, ruleSet, prefixMappingTable)

                    {

                        var mainRProcessor = __makeRuleProcessor(ruleSet, prefixMappingTable);

                     

                     

                      // if __processTree() fails with an exception,

                      // delete ruleProcessor and throw e

                      try {

                      __processTree(root, mainRProcessor);

                        __deleteRuleProcessor(mainRProcessor);

                      } catch (e) {

                        __deleteRuleProcessor(mainRProcessor);

                        throw e;

                        }

                    }

                     

                     

                    function __processTree (root, rProcessor)

                    {

                      var ruleProcessor = rProcessor.ruleProcessor;

                      try

                      {

                         var matchData = ruleProcessor.startProcessingRuleSet(root);

                      __processMatchData(matchData, rProcessor);

                      

                      ruleProcessor.endProcessingRuleSet();

                      }

                      catch (e)

                      {

                      // no longer deleting ruleProcessor within __processTree

                      // deletion occurs either in __processRuleSet, or external

                      // to glue code.

                      ruleProcessor.endProcessingRuleSet();

                      throw e;

                      }

                    }

                     

                     

                    function __processChildren(rProcessor)

                    {

                      var ruleProcessor = rProcessor.ruleProcessor;

                      try

                      {

                      var matchData = ruleProcessor.startProcessingSubtree();

                      __processMatchData(matchData, rProcessor);

                      }

                        catch (e)

                        {

                            ruleProcessor.halt();

                            throw e;

                        }

                    }

                     

                     

                    function __processMatchData(matchData, rProcessor)

                    {

                      var ruleProcessor = rProcessor.ruleProcessor;

                      var ruleSet = rProcessor.ruleSet;

                      while (matchData != undefined)

                      {

                      var element = matchData.element;

                      var matchRules = matchData.matchRules;

                      var applyMatchedRules = true;

                     

                     

                      // apply the action of the rule.

                      // Continue applying rules as long as the apply function returns false.

                      for (var i=0; i<matchRules.length && applyMatchedRules && !ruleProcessor.halted; i++)

                      {

                      applyMatchedRules = (false == ruleSet[matchRules[i]].apply(element, rProcessor));

                      }

                      matchData = ruleProcessor.findNextMatch();

                      }

                    }

                     

                     

                    function __skipChildren(rProcessor)

                    {

                      rProcessor.ruleProcessor.skipChildren();

                    }