12 Replies Latest reply on Apr 18, 2016 3:19 AM by karthiks94217840

    xml work flow: auto flow

    karthiks94217840 Level 2

      Dear java king,

       

      I write a script to import xml and place it in text frame but I had my overset text, i know that it just a shift+doubleclick in outport of text frame to autoflow text, the problem is how can i write it in a script? please help and suggest friend

       

      How to solve this type of problem. 

       

      Thanks in advance!

        • 1. Re: xml work flow: auto flow
          tpk1982 Level 4

          use this

           

          var doc=app.activeDocument
          doc.textPreferences.smartTextReflow=true; 
          doc.textPreferences.addPages = AddPageOptions.END_OF_STORY; 
          doc.textPreferences.limitToMasterTextFrames = true; 
          doc.textPreferences.preserveFacingPageSpreads = false; 
          doc.textPreferences.deleteEmptyPages = true;
          
          • 2. Re: xml work flow: auto flow
            karthiks94217840 Level 2


            Thanks tpk.


            Problem not solved tpk. see my below coding. I thing, the following problem based on the merging.

             

             

            var docmentxml = File.openDialog ("Choose the Template Open file *.xml", "*.xml", false );

              if (docmentxml != null) { 

                var myDocument  = app.activeDocument.importXML(File(docmentxml));


            var doc = app.activeDocument;

            doc.textPreferences.smartTextReflow=true;  

            doc.textPreferences.addPages = AddPageOptions.END_OF_STORY;  

            doc.textPreferences.limitToMasterTextFrames = true;  

            doc.textPreferences.preserveFacingPageSpreads = false;  

            doc.textPreferences.deleteEmptyPages = true;

            }


            And, my screenshot also

            Screen Shot 2016-04-15 at 2.31.50 PM.png


            Please suggest tpk.


            Thanks



            • 3. Re: xml work flow: auto flow
              tpk1982 Level 4

              Your document needs two pages with a text frame on each page, and the frames have to be threaded.

              page.png

               

               

              main();
              function main(){
              //xml -  import options
              var myDocument = app.activeDocument;
              var myXMLImportPreferences = myDocument.xmlImportPreferences;
              myXMLImportPreferences.allowTransform = false;
              myXMLImportPreferences.createLinkToXML = true;
              myXMLImportPreferences.ignoreUnmatchedIncoming = false;
              myXMLImportPreferences.ignoreWhitespace = false;
              myXMLImportPreferences.importCALSTables = false;
              myXMLImportPreferences.importStyle = XMLImportStyles.appendImport;
              myXMLImportPreferences.importTextIntoTables = false;
              myXMLImportPreferences.importToSelected = false;
              myXMLImportPreferences.removeUnmatchedExisting = false;
              myXMLImportPreferences.repeatTextElements = false;
              
              var myFolder= Folder.selectDialog("Select the path...", ""),
                  myFiles = myFolder.getFiles("*.xml");
              for(var i=0;i<myFiles.length;i++)
                  {
                          if (myFiles[i] != null)
                  {
                          myFiles[i].open("read", "text");
                          testq = myFiles[i].read();
                          myFiles[i].close();
                          } else
                              return false;
                          myDocument.importXML(File(myFiles[i]), false);
                          var myDocument = app.activeDocument;
                          myDocument.xmlElements.item(0).placeXML(myDocument.pages.item(0).textFrames.item(0));
                          myDocument.textPreferences.smartTextReflow = true;
                          app.activeDocument.recompose();
              
                  }
              }
              
              
              • 4. Re: xml work flow: auto flow
                karthiks94217840 Level 2

                Hi tpk,

                 

                Thank for your coding

                 

                @Sorry for the say: Again, that problem not solved tpk attached screenshot for your reference.

                 

                @One more doubt: I use your code to flow the file. But, that xml contend flowing for inside of <Root> element see screenshot below. But, i am using Manuel importXML option, that <Root> element automatically removed.

                                               What the reason for "Java script importXML" with " Manuel importXML"? Please explain me friend.

                 

                Herewith no need <Root> element after flowing file.

                 

                 

                Screen Shot 2016-04-15 at 7.33.23 PM.png

                 

                Thanks

                • 5. Re: xml work flow: auto flow
                  Loic.Aigon Adobe Community Professional

                  Before any scripting concerns, is the frame inherited from the master ? Otherwise I can't see how InDesign could know where to reflow anything

                   

                  Loic

                  • 6. Re: xml work flow: auto flow
                    karthiks94217840 Level 2

                    HI TPK and Loic.

                     

                    Loic.Aigon: Yes right. I have newly create the master page. Since, autoFlow working super. Thanks your nice explain

                     

                    tpk1982: Really very very thanks tpk. your code working good. AutoFlow success

                     

                    One more doubt: After, flow the file continue for <Root> element. But, I want to remove  <Root> element? that is passible to script Tpk and Loic. Screenshot below.

                     

                    Screen Shot 2016-04-16 at 10.33.31 AM.png

                     

                    Thanks,

                    • 7. Re: xml work flow: auto flow
                      karthiks94217840 Level 2

                      Hi friend,

                       

                      Any suggestion in my above question friend. Please replay me

                       

                      Advance Thanks

                      • 8. Re: xml work flow: auto flow
                        tpk1982 Level 4

                        Why you want to remove Root? Is it base of xml, if you remove this then you lost all text, isn't it?

                         

                        but you can use untag command to remove a tag in javascript

                        • 9. Re: xml work flow: auto flow
                          karthiks94217840 Level 2

                          Hi Tpk,

                           

                          Thanks your replay

                           

                          Tpk: Yes you are right, Root tag base of xml, but after that export to xml and validation stage not valid for  <Root> tag.

                          That only reason i want to remove the root tag.

                           

                          Thanks

                          • 10. Re: xml work flow: auto flow
                            tpk1982 Level 4

                            this line will untag all xml from the document:

                             

                            app.activeDocument.xmlElements.item(0).xmlElements.everyItem().untag();
                            

                             

                             

                            or if you need replace with any other xml tag use this

                             

                            var myDocument = app.activeDocument;
                            var myTags = myDocument.xmlTags;
                            for(var l=myTags.length-1; l>=0; l--){
                                if(myTags[l].name == "Root"){
                                    var xmlTag = myTags[l];
                                    xmlTag.remove("mytag");// here i am replacing mytag with Root
                                }
                            }
                            
                            • 11. Re: xml work flow: auto flow
                              Sajeev Sridharan Level 4

                              Change the below line:

                               

                              myXMLImportPreferences.importStyle = XMLImportStyles.appendImport;

                               

                              to

                               

                              myXMLImportPreferences.importStyle = XMLImportStyles.mergeImport;

                              • 12. Re: xml work flow: auto flow
                                karthiks94217840 Level 2

                                Hi Tpk

                                 

                                Very very thank

                                 

                                Exactly working your below coding TPK. Really you are super TPK.

                                 

                                myXMLImportPreferences.importStyle = XMLImportStyles.mergeImport;

                                 

                                Thanks - Like you