6 Replies Latest reply on Jun 8, 2012 1:58 AM by [Jongware]

    How get the untagged contents using JS?

    Praveen10 Level 1

      Hi All,

       

      Pl. give me the hint to get the untagged contents using JS?

       

      Thanks in advance.

       

      Praveen

        • 1. Re: How get the untagged contents using JS?
          Cenchen Level 2

          Hi Praveen,

                             

                              Did you complete this? If yes pls give me the points...

           

                                  Thanks in advance...

          • 2. Re: How get the untagged contents using JS?
            Loic.Aigon Adobe Community Professional

            Hi,

            untagged content has null associatedXMLElement. Once that said, loop through all the contents and check the associatedXMLElement value.

            Loic

            http://www.loicaigon.com

            • 3. Re: How get the untagged contents using JS?
              Cenchen Level 2

              The untagged content has not null associatedXMLElement because its getting root XMLElement in such case....so how to find untagged content?

              • 4. Re: How get the untagged contents using JS?
                Loic.Aigon Adobe Community Professional

                Hi,

                 

                I am surprised you get that result. If an item isn't tagged, there is no way you get returned the root xml element.

                 

                Given some content of an untagged text frame :

                app.selection[0].associatedXMLElements //undefined

                 

                Unless teh content makes part of some tagged textframe, which may return the associatedXMLElements of the parent and even then, no content can be associated with the root as every tagged contents are children of the root. Do you have screenshot ?

                 

                Loic

                • 5. Re: How get the untagged contents using JS?
                  Cenchen Level 2

                  Mid.JPG

                       The above fig represents, the selected text has placed in the middle of the "sec" tag content. so its associated element is "sec" only.

                   

                  End.JPG

                       This fig, selected text has placed in an end of the document. so its associated element is root tag "book".

                   

                  So how can I find the untagged content through InDesign javascript?

                  • 6. Re: How get the untagged contents using JS?
                    [Jongware] Most Valuable Participant

                    I see from that image where Loic's confusion comes from.

                     

                    That paragraph you marked is not really "untagged". If you look in the Tags panel or XML Structure pane, you will see it *is* tagged, with whatever the root object is from the tags above and below this line.

                     

                    In your first example, the tagged path is "body/sec", according to the Structure pane. But what do you mean this?

                     

                    ... so its associated element is "sec" only.

                     

                    I mean, it's clear that the paragraph in itself does not have a tag. But attempting to check if an entire paragraph is not tagged seems to be a bit tricky -- I just tried with the following script (and some variations), and got mixed results.

                     

                    s = app.selection[0].parentStory;
                    for (pp=0; pp<s.paragraphs.length; pp++)
                    {
                    p = s.paragraphs[pp];
                    if (p.associatedXMLElements && p.associatedXMLElements[0].parent)
                    {
                      if (!confirm (p.contents+"\r=>"+p.associatedXMLElements[0].parent.markupTag.name)) exit();
                    }
                    }