3 Replies Latest reply on Aug 7, 2010 1:07 AM by PankChat

    Inserting text and applying XMLTags to it

    PankChat Level 1

      Hello all,

       

      What will be correct syntax for inserting a specified text and surrounding it with available text. I tried below but seems to be wrong syntax:

       

      myDoc.pages[0].textFrames.itemByName("main").insertionPoints.item(0).properties = {markup tag:"anchor", XML content:myText}

       

      Any suggestions please.

       

      Pankaj

        • 1. Re: Inserting text and applying XMLTags to it
          PankChat Level 1

          I even tried

           

              myDoc.pages[0].textFrames.itemByName("main").insertionPoints.item(0).properties = {markupTag:"anchor", xmlContent:myText};

          but doesn't seems to be working.

           

          Normally ESTK highlights error while saving to jsxbin but it doesn't in this case.

           

          Can this be done in JS?

           

          Any guidance will really appreciated.

          • 2. Re: Inserting text and applying XMLTags to it
            PankChat Level 1

            Sorry I should have mentioned earlier:

             

            IDCS3[MAC]

             

            Okay tried to apply xmlTags in context of xmlEleme

            nts

             

            for (var i=0; i<=myTotalPage-1; i++)

            {

            app.activeWindow.activePage =myDoc.pages[i];

                var myText=myDoc.pages[i].name;

             

             

            if(myDoc.pages[i].textFrames.itemByName("sections").insertionPoints.length==0)

            {//Do nothing}

            else{

            var myRootXMLElement = myDoc.xmlElements.item(0);

            var myXMLTag = myDoc.xmlTags.itemByName("anchor");

            var myXMLElementA = myRootXMLElement.xmlElements.add(myXMLTag);

            myXMLElementA.xmlAttributes.add("id",myText);

            var page_id_frame= myDoc.pages[i].textFrames.itemByName("main");

             

            //page_id_frame.insertionPoints.item(0).placeXML (myXMLElementA); // I cannot do that because placeXML () will only place this *only element* and I need to insert the element in xml story at the top of "main" frame on each page.

            }

            }

             

            page_id_frame.insertionPoints.item(0).properties = {markupTag:myXMLElementA};// Does not work. Seems to be incorrect syntax.

             

            Now I've elements added to root element as <anchor id="1"> <anchor id="2"> <anchor id="3"> and so on (though I want it to be empty tag) and it will be added to root element in structure. I even can manage deleting these while exporting xml but cannot figure out how to add xmlTags with attribute values to each page.

             

            The other idea comes in my mind to select text and surrund it with desired tag. Cannot figure out how to do it in scripting.

            I mean which is only two step activity using UI =>select the text =>tag it using [Tags] panel.  Can't we do that with JS.

             

            Can anybody throw some idea.

             

            Pankaj

            • 3. Re: Inserting text and applying XMLTags to it
              PankChat Level 1

              Finally I am able to appl

              y xmlTags on top of every page (with unique attibute value).

              Changed snippet looks like below.

               

              for (var i=0; i<=myTotalPage-1; i++)

               

              {
              app.activeWindow.activePage =myDoc.pages[i];
              var myText="{p"+myDoc.pages[i].name+"}";

               

              if(myDoc.pages[i].textFrames.itemByName("main").insertionPoints.length==0){}
              else{

               

              var myRootXMLElement = myDoc.xmlElements.item(0);
              var myXMLTag = myDoc.xmlTags.itemByName("anchor");

              var myStory=myDoc.pages[i].textFrames.itemByName("main").insertionPoints.item(0);
              try

              {var myXMLElement=myStory.texts.item(0).associatedXMLElements[0].xmlElements.add({markupTag:my XMLTag});

                   myXMLElement.xmlAttributes.add("id",myText);

                   myStory.insertionPoints.item(0).markup(myXMLElement);

              }catch(e){}
              }
              }

               

              Only one issue left is

               

              var  myXMLElement=myStory.texts.item(0).associatedXMLElements[0].xmlElements.add({markupTag:my XMLTag});

              //Outputs me error if the page has multiple textFrames labelled "main".//Object is undefined. I skipped the error with try/catch block to keep executiion of script but I miss the required info on that page.

               

              Is there a smart way to select single "main" frame (hich is first and top one) or I have to compare the geometricBounds to get the correct one?

               

              Thanks for your patience and reading.

               

              Pankaj