5 Replies Latest reply on Mar 3, 2014 9:33 PM by BEGINNER_X

    Find Stories without XML tag

    BEGINNER_X Level 3

      Hi All,

       

      I hope this should be a simple request for you, and am entirely new for the XML jobs.

       

      Need to find the texts without having xml tags in the xml workflow.

       

      Trying coding is below:

       

      var myDoc = app.activeDocument;
      
      var myStories = app.activeDocument.stories.everyItem().getElements();
      
      alert(myStories.length)
      
      for(i=0; i<myStories.length; i++)
      {
              if(myStories[i].texts[0].xmlTags.isValid = false)
          {
              alert("Stories not having XML tag")
              }
          else
          {
              alert("No issues")
              }
          }
          //~     if(myStories[i].texts[0] != app.activeDocument.xmlElements[0])
      //~     {
      //~         alert("Stories not having XML tag")
      //~         }
      //~     }
      

       

      Kindly help for my request.

       

      Thanks in advance

      Siraj

        • 1. Re: Find Stories without XML tag
          BEGINNER_X Level 3

          Hi All,

           

          Any update for my request.

           

          Regards

          SIraj

          • 2. Re: Find Stories without XML tag
            Daniel Sterchi Adobe Community Professional

            Hi Beginner_X

             

            How big will, or is the document with XML?

            How many XML-Elements are in the document (10 100 1000)?

             

            I can think of two sollutions to the qestion. It depends on how many XML-Elements there are in the document.

             

            kind Regards

             

            Dani (from Switzerland)

            • 3. Re: Find Stories without XML tag
              BEGINNER_X Level 3

              Hi Dani,

               

              Thanks for your response...

               

              In the XML flow job, wrongly composers keyed in the document like marginal notes  etc...

               

              So the script need to find the contents without having XML tags in the active document.

               

              Hope you understand my requirement.

               

               

              Regards

              Siraj

              • 4. Re: Find Stories without XML tag
                Daniel Sterchi Adobe Community Professional

                Hi Siraj

                 

                I had to deal with an emergency so I couldn’t answer until now.

                I’ve put together a few lines of code in the hope that these is the answer to your question.

                 

                The script finds all the stories without an XML-Tag. It will also find all your headings & footers if there is no XML-Tag found in these stories.

                 

                Kind regards

                 

                Daniel (from Switzerland)

                 

                #target InDesign

                 

                // this JavsScript must be imported. You find it in the JavaScript directory under the Application directory

                // for the Mac this is: /Application/Adobe InDesign CC/Scripts/XML Rules

                #include "glue code.jsx"

                 

                main();

                exit();

                 

                function main() {

                 

                          var myDoc = app.activeDocument;

                          var myStories = myDoc.stories.everyItem().getElements();

                          var idArray = new Array(0);

                          var storyArray = new Array(0); 

                 

                          // store all stories of the document in an array

                          for(var j=0; j < myStories.length; j++) {

                                    storyArray.push(myStories[j].id);

                          }

                 

                // *** here start the XML-Rules ******************************//

                          var elements = myDoc.xmlElements;

                          var myRuleSet = new Array(

                                    alleObj = new all(idArray)

                          );

                 

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

                // *** here stop the XML-Rules *******************************//

                 

                          // compare the two arrays. This may last a moment, if the Document is big

                          // thats why I asked about the Sitze of your document

                          for (var i=0; i < idArray.length; i++) {

                                    for (var k=0; k < storyArray.length; k++) {

                                              if (idArray[i] == storyArray[k]) {

                 

                                                        // if the story-id is found in both array, set the element in the

                                                        // story-array to -1 for later

                                                        storyArray[k] = -1;

                                              }

                                    }

                          }

                 

                          // find all the elements in the story-array in which the value

                          // is greater of 0

                          for (var i=0; i < storyArray.length; i++) {

                                    if (storyArray[i] > 0) {

                 

                                              // so here you are. There you have the id of the stories

                                              // in which there alre no XML-elements

                                              alert(storyArray[i]);

                                    }          // if …

                          }          // for()

                }          // main()

                 

                // XML-Rule

                function all(idArray) {

                          this.name = "all";

                          this.xpath = "//*";

                          this.apply = function(myElement, myRuleProcessor) {

                 

                                    var storyId = myElement.parentStory.id;

                 

                                    var i=0, found = false;

                                    while ((i < idArray.length) && (!found)) {

                                              if (idArray[i++] == storyId) found=true;

                                    }

                 

                                    // store anly the number of the stories which are not stored up to now

                                    if (!found) idArray.push(storyId);

                 

                                    return true;

                          }          // this.apply

                 

                }          // all()

                 

                 

                • 5. Re: Find Stories without XML tag
                  BEGINNER_X Level 3

                  Dear Dani,

                   

                  Apologies for the late response...

                   

                  Thank You for your valuable coding....

                   

                  Its working fine in my end.

                   

                  Is there any other way to find the same output?

                   

                  for(i=0; i<myStories.length; i++)
                  {
                          if(myStories[i].texts[0].xmlTags.isValid = false)
                      {
                          alert("Stories not having XML tag")
                          }
                      else
                      {
                          alert("No issues")
                          }
                      }

                   

                  [Note: It should be a simple document]

                   

                  Thanks

                  Siraj