4 Replies Latest reply on Sep 6, 2016 12:43 AM by csm_phil

    XML: Insert \r after last element with insertionPoints

    borise78101190

      Hallo!

       

      I import some transformed XML into InDesign and some Javascript to modify the output.

       

      <contacts>

           <contact type="phone">123 456</contact>

           <contact type="phone">5232 222</contact>

           <contact type="phone">342 423</contact>

           ...

      </contacts>

       

      To set characterStyles I have following code:

       

      function AddLabel(){

        this.name = "AddLabel";

        this.xpath = "//contact[@type = 'phone']";

        this.apply = function(myElement, myRuleProcessor){

          with(myElement){

            var myAttribute = myElement.xmlContent;

            myAttribute.applyCharacterStyle(app.activeDocument.characterStyles.item("bold blue"), true); }

          return false;

        }

      }

       

      I would like to add an line break (\r) after the last element.

       

      But using this line of code doesn't work:

      myAttribute.insertionPoints[lastitem()].contents  = String('\r');

       

      Any other approach I tried fails as well.

      Any hint is highly appreciated!