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

    XML: Insert \r after last element with insertionPoints




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



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

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

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




      To set characterStyles I have following code:


      function AddLabel(){

        this.name = "AddLabel";

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

        this.apply = function(myElement, myRuleProcessor){


            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!