4 Replies Latest reply on Oct 14, 2014 10:01 PM by Sajeev Sridharan

    alert Content for text without any XML tag

    BEGINNER_X Level 3

      Hi All,

       

      For the XML workflow,

       

      Need a alert content or select content for the text without any xml tag.

       

      Please help for my XML job request.

       

      Regards

      Siraj

        • 1. Re: alert Content for text without any XML tag
          BEGINNER_X Level 3

          Hi All,

           

          New to XML, just learning stage only.

           

          Already I asked and got the coding through forum. It alert text frame ID only.

           

          But, guide me how to get the

           

          1. alert or select the contents.

          2. alert the page number or select text frame etc.

           

          Coding is below:

           

          #target InDesign
          
          #include "/Applications/Adobe InDesign CS6/Scripts/Xml Rules/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 *******************************//
                    for (var i=0; i < idArray.length; i++) {
                              for (var k=0; k < storyArray.length; k++) {
                                        if (idArray[i] == storyArray[k]) {
                                                  storyArray[k] = -1;
                                        }
                              }
                    }
          
                    for (var i=0; i < storyArray.length; i++) {
                              if (storyArray[i] > 0) {
                                        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()
          

           

          Regards

          Siraj

          • 2. Re: Re: alert Content for text without any XML tag
            Sajeev Sridharan Level 4

            Try this,

             

            var myDoc = app.activeDocument;
            var myPages = myDoc.pages;
            for(i=0; i<myPages.length; i++)
            {
                var myStories = myDoc.pages[i].textFrames;
                for(j=0; j<myStories.length; j++)
                {
                    myStories[j].texts[0].select();
                    try{
                        myStories[j].texts[0].associatedXMLElements[0].isValid;
                    }
                    catch(e){
                        myStories[j].texts[0].select();//Select the non-XML content
                        alert(myStories[j].texts[0].contents)//displays the non-XML content
                    }
                }
            }
            
            
            

             

            Vandy

            • 3. Re: alert Content for text without any XML tag
              BEGINNER_X Level 3

              Hi Vandy,

               

              Working fine for the separate stories.

               

              I have one more clarification, if any single paragraph is untag by composer, then it should possible to alert that contents too.

               

              Regards

              Siraj

              • 4. Re: alert Content for text without any XML tag
                Sajeev Sridharan Level 4

                Hi Siraj,

                 

                If a single paragraph is un-tagged by operator, then you have to validate the paragraph with parent tag or root tag.

                 

                It will be untag text, but it doesn't mean that it doesn't have parent tag.

                 

                e.g.,

                <root>

                <chapter>

                <para>Sample Text</para>

                Sample Text //here this is an non-xml content, but it is under <root> and <chapter> tag, it doesn't mean that this is non-xml content.

                <para>Sample Text</para>

                <para>Sample Text</para>

                <para>Sample Text</para>

                </chapter>

                </root>

                 

                Hope you understand!

                 

                Vandy