4 Replies Latest reply on Jun 11, 2008 12:13 AM by (hp_)

    [CS3] [JS] add XML  Element to Insertion Points

      hi list,

      i'll do some text parsing in indesign cs3 intended to add some xml elements to my document.
      i just wonder why i can't markup an insertion point. is the following approach correct? The code works fine, only the return value (stored in the _xml variable) is not the new element but the parent element. The same code works without using the insertion point (marking up the text object [xmlElements.add(_dokument.xmlTags.item("index") , erg[0]))] ).
      Any ideas or thoughts?

      var _dokument = app.activeDocument;

      main ();

      // ** main ()
      function main() {
      //Set the find options.
      app.findGrepPreferences = NothingEnum.nothing;
      app.changeGrepPreferences= NothingEnum.nothing;

      //find any string encloased by @
      app.findGrepPreferences.findWhat = "@.*?@";

      erg = _dokument.findGrep();

      while (erg.length > 0) {
      _xml = _dokument.xmlElements[0].xmlElements.item("text").xmlElements.add(_dokument.xmlTags.item( "index") , erg[0].insertionPoints[0]);
      erg[0].contents = "";
      erg = _dokument.findGrep();
        • 1. Re: [CS3] [JS] add XML  Element to Insertion Points
          Level 1
          If you try it in the UI, you'll see that when only an insertion point is selected and you try to tag it, the whole story is tagged.

          I don't think that what you're trying can be done. You have to tag content, not the lack of it. However, what you could do is insert some temporary text at the insertion point, tag that and then delete the text. That will have the effect you're trying to achieve.

          • 2. Re: [CS3] [JS] add XML  Element to Insertion Points
            Level 1
            ...but you can enter a character in the contents of the insertion point, tag it, and then delete the character. This creates an empty element at the insertion point. Not elegant, but it works.:-)


            • 3. Re: [CS3] [JS] add XML  Element to Insertion Points
              Level 1
              hi dave,

              gui testing is always a good idea :-) but in this case the behaviour is different:
              your observation is correct (anyway at least a strange behaviour compared to any xml editing tool i know == how adobe intended to insert an empty element?), tagging in the gui a tagged insertion point tags the whole story.
              in the script a new element is added but the return value is the parent element (the xmlElement of the whole story).
              this causes a problem when i add an attribute (the intention of the above script is to add references) which is added to the parent element.

              • 4. Re: [CS3] [JS] add XML  Element to Insertion Points
                Level 1
                hi olav,

                maybe i'm not firm with insertion points, but your solution does not work:

                _insert = erg[0].insertionPoints[0];
                _insert.contents = "i";
                _xml = dokument.xmlElements[0].xmlElements.item("text").xmlElements.add(_dokument.xmlTags.item(" index") , _insert );

                leads to the following xml structure: fooi foo and the same behaviour as in the reply to dave encounters (return value = parent element)

                do i use the contents attribute correct?