1 Reply Latest reply on Oct 28, 2009 6:24 AM by Thomas B. Nielsen

    [CS3][JS] Apply XML tag for selected text




        I need to apply XML tag to selected text in a tagged content.The XML tag is already applied for paragraph.I need to apply XML Tag for selected text in a paragraph.


      I have used following code, it applies tag for entire paragraph,not a selected text in a paragraph.





      Please suggest me.





        • 1. Re: [CS3][JS] Apply XML tag for selected text
          Thomas B. Nielsen Level 3

          The example script, markup.jsx


          //An InDesign CS4 JavaScript
          //Shows how to use the markup method.
          function main(){
          function mySetup(){
              var myDocument = app.documents.add();
              var myPage = app.activeWindow.activePage;
              var myRootXMLElement = myDocument.xmlElements.item(0);
              var myXMLTag = myDocument.xmlTags.add("xml_element");
              var myXMLElementA = myRootXMLElement.xmlElements.add(myXMLTag);
              myXMLElementA.contents = "This is a paragraph in an XML story.";
              var myTextFrame = myPage.textFrames.add({geometricBounds:myGetBounds(myDocument, myPage)});
              myTextFrame.contents = "This is the first paragraph in a text frame.\rThis is the second paragraph in a text frame.\rThis is the third paragraph in a text frame.\rThis is the fourth paragraph in a text frame.\r";
          function mySnippet(){
              var myDocument = app.documents.item(0);
              var myPage = myDocument.pages.item(0);
          function myTeardown(){
          function myGetBounds(myDocument, myPage){
              var myPageWidth = myDocument.documentPreferences.pageWidth;
              var myPageHeight = myDocument.documentPreferences.pageHeight
              if(myPage.side == PageSideOptions.leftHand){
                  var myX2 = myPage.marginPreferences.left;
                  var myX1 = myPage.marginPreferences.right;
                  var myX1 = myPage.marginPreferences.left;
                  var myX2 = myPage.marginPreferences.right;
              var myY1 = myPage.marginPreferences.top;
              var myX2 = myPageWidth - myX2;
              var myY2 = myPageHeight - myPage.marginPreferences.bottom;
              return [myY1, myX1, myY2, myX2];


          I think you can use the markup function on the selected item (Text Object have a markup method)




          Thomas B. Nielsen


          1 person found this helpful