1 Reply Latest reply on Jul 21, 2008 7:43 AM by (Thomas_Bolbro_Nielsen)

    [CS3 JS] XML markup with a loop

    Level 1
      Hello,

      I'm creating a script that outputs a calendar list for a month into a textframe in Indesign. I would like to have each line (representing a day) marked up with a tag (monday to tag "monday").
      I'm using the function below, but i is not creating a XML element for each line/day, instead it creates one xmlelement and updates it.

      Can anyone guide me here?
      I have tried to read the manual, i have read other topics like //MarkupTextWithGrep.jsx by Olav Kvern, but i just cant make this work.

      function monthlist(item, date, xmlElm) { // Item is a textframe, date is a date object, xmlElm is the textframes associatedXMLElement
      item.contents = "";
      var count = 0;
      for (cur_date = new Date(date.getFullYear(), date.getMonth(), date.getDate()); cur_date.getMonth() == date.getMonth(); cur_date.setDate(cur_date.getDate()+1)) {
      if(count != 0) {
      item.contents += "\r"
      }
      item.contents += "\t" + cur_date.getDate();

      // xmlMarkup(cur_date.getFullDay(),item.lines.lastItem());
      // Create the xml tag if it does not already exist.
      try{
      myXMLTag = act_doc.xmlTags.item("_" + cur_date.getDay().toString());
      myXMLTag.name;
      }
      catch (myError){
      myXMLTag = act_doc.xmlTags.add("_" + cur_date.getDay().toString());
      }
      xmlElm.xmlElements.add(myXMLTag, item.lines.lastItem());
      count++;
      }
      }