10 Replies Latest reply on May 8, 2013 4:23 AM by Chinnadk

    How to move some xml element and its content to a new frame

    Chinnadk Level 4

      Hi All,

       

      How to move some xml element and its content to a new frame.

        • 1. Re: How to move some xml element and its content to a new frame
          csm_phil Level 4

          Hi Chinnadk,

           

          Please try the below JS code, Its move the margintag text into the anchored text frame and applied the object style also.

           

          #target InDesign;
          
          #include "/Program Files (x86)/Adobe/Adobe InDesign CS5.5/Scripts/XML Rules/glue code.jsx"
          
          var myDoc = app.activeDocument;
          
          //____________________ XML RULE SET
          var myRuleSet = new Array (new margintag); 
          with(myDoc){
              var elements = xmlElements;
              __processRuleSet(elements.item(0), myRuleSet);
          }
          
          
          function margintag(){
              this.name = "margintag";
              //this.xpath = "//margintag[@type='mn2']";
              this.xpath = "//margintag";
              this.apply = function(myElement, myRuleProcessor){
                  with(myElement){
                      app.select(myElement);
                      try{
                          var myPrePara = app.selection[0].paragraphs[-1].parentTextFrames[0].paragraphs.previousItem(app.selection[0].paragraphs[-1]);
                          if(myPrePara.characters[-1].contents=="\r"){
                              myPrePara.characters[-1].remove();
                              }
                          var myTextframe = myElement.placeIntoInlineFrame(["7p9","6p"]);
                          myTextframe.appliedObjectStyle= myDoc.objectStyles.item("MN1");
                          myTextframe.fit(FitOptions.FRAME_TO_CONTENT);
                          myTextframe.parentStory.paragraphs.everyItem().appliedParagraphStyle = app.activeDocument.paragraphStyles.itemByName("MN1");
                          }catch(e){}
                      app.selection = null;
                      }
                  return true;
                  }
              }
          

           

           

          thx,

          csm_phil

          • 2. Re: How to move some xml element and its content to a new frame
            Chinnadk Level 4

            Hi csm_phil,

             

            Thanks for your help, but it showing an error "__processRuleSet is not a function"

            • 3. Re: How to move some xml element and its content to a new frame
              csm_phil Level 4

              Hi Chinnadk,

               

              Which version of InDesign your using and Platform also. I have gave the folder path is InDesign CS5.5 Windows.

               

              You just copied this JS code and save the InDesign Script Panel folder path with any script name. It will appear into the InDesign Script panel and run through here.

               

              thx,

              csm_phil.

              • 4. Re: How to move some xml element and its content to a new frame
                Chinnadk Level 4

                Hi csm_phil,

                 

                Sorry, im very new to indesign scripting i cant able to understand your script. Why your calling gluecode.jsx? if possible can you explain your script step by step.

                 

                Regards

                Chinna

                • 5. Re: How to move some xml element and its content to a new frame
                  csm_phil Level 4

                  Hi ChinnaDK,

                   

                  I have inlcude the glue code.jsx is iteraete the xml element. If you want clearly understand what i did. please down load the below link scripting guide for JS. and go to page 187 XPath details given breif explanation.

                   

                  http://wwwimages.adobe.com/www.adobe.com/content/dam/Adobe/en/devnet/indesign/cs55-docs/In DesignScripting/InDesign-ScriptingGuide-JS.pdf

                   

                  my js code is working or not at your end.

                   

                  thx,

                  csm_phil

                  • 6. Re: How to move some xml element and its content to a new frame
                    Chinnadk Level 4

                    Hi csm_phil,

                     

                    Thanks for your help ill try this.

                    • 7. Re: How to move some xml element and its content to a new frame
                      csm_phil Level 4

                      Hi Chinnadk,

                       

                      Sorry my code its comment some lines. Now only I check the forum thread, you just try one more time.

                       

                       

                      #target InDesign;
                      
                      #include "/Program Files (x86)/Adobe/Adobe InDesign CS5.5/Scripts/XML Rules/glue code.jsx"
                      
                      var myDoc = app.activeDocument;
                      
                      //____________________ XML RULE SET
                      var myRuleSet = new Array (new margintag); 
                      with(myDoc){
                          var elements = xmlElements;
                          __processRuleSet(elements.item(0), myRuleSet);
                      }
                      
                      
                      function margintag(){
                          this.name = "margintag";
                          //this.xpath = "//margintag[@type='mn2']";
                          this.xpath = "//margintag";
                          this.apply = function(myElement, myRuleProcessor){
                              with(myElement){
                                  app.select(myElement);
                                  try{
                                      var myPrePara = app.selection[0].paragraphs[-1].parentTextFrames[0].paragraphs.previousItem(app.selection[0].paragraphs[-1]);
                                      if(myPrePara.characters[-1].contents=="\r"){
                                          myPrePara.characters[-1].remove();
                                          }
                                      var myTextframe = myElement.placeIntoInlineFrame(["7p9","6p"]);
                                      myTextframe.appliedObjectStyle= myDoc.objectStyles.item("MN1");
                                      myTextframe.fit(FitOptions.FRAME_TO_CONTENT);
                                      myTextframe.parentStory.paragraphs.everyItem().appliedParagraphStyle = app.activeDocument.paragraphStyles.itemByName("MN1");
                                      }catch(e){}
                                  app.selection = null;
                                  }
                              return true;
                              }
                          }
                      

                       

                       

                      thx,

                      csm_phil

                      • 8. Re: How to move some xml element and its content to a new frame
                        Chinnadk Level 4

                        Hi csm_phil,

                         

                        Yes now its working fine thank you but it extracting only the content. Is there any way to get contents along with tags.

                         

                        Regards,

                        Chinna

                        • 9. Re: How to move some xml element and its content to a new frame
                          csm_phil Level 4

                          Hi Chinnadk,

                           

                          You don't worry the xml tags appeared in the xml structure, you just export the XML the texts contaings the tag. also check with xml structure in InDesign.

                           

                          Note: if my script help full to you just apply help full answer or perfect answer. This you have to follow all the request in forum.

                           

                          thx,

                          csm_phil.

                          1 person found this helpful
                          • 10. Re: How to move some xml element and its content to a new frame
                            Chinnadk Level 4

                            Thanks csm_phil, sure ill do as you said above.