1 Reply Latest reply on Aug 7, 2018 2:52 AM by Loic.Aigon

    Indesign tagging text with two tags




      I need to tag a text twice in extendscript.



      A simple example below:


      var textStyleRanges = app.selection[0].texts[0].textStyleRanges.everyItem().getElements(); //I have a textFrame Selected
      app.activeDocument.xmlElements.item(0).xmlElements.add ("Story", app.selection[0]); //I tag the frame with Story
      app.activeDocument.xmlElements.item(0).xmlElements.add ("Tag1", textStyleRanges[0]); //I add Tag1
      app.activeDocument.xmlElements.item(0).xmlElements.add ("Tag2", textStyleRanges[0]); //I would like to add Tag2 inside Tag1


      Now I need to add another tag inside Tag1 for the same text so it looks like this

      <Tag1><Tag2>My text</Tag2></Tag1>


      The problem is, when adding Tag2, The first tag gets replaced with Tag2 so it looks like this:

      <Tag2>My text</Tag2>


      I Understand why, but not how to solve it like I would like.


      Any suggestions?

        • 1. Re: Indesign tagging text with two tags
          Loic.Aigon Adobe Community Professional

          As you tag, references change (added tag characters push indeces away). Reference again your tag.


          var tf = app.selection[0];
          var txt = tf.parentStory.texts[0];
          var doc = app.activeDocument;
          var root = doc.xmlElements.item(0);
          root.xmlElements.add ("Story", tf);
          txt = root.xmlElements.add ("Tag1", txt ).xmlContent.texts[0];
          root.xmlElements.add ("Tag2", txt );


          Out of check on the context (sel, story…).