2 Replies Latest reply on Jun 10, 2009 2:18 PM by Thomas B. Nielsen

    [JS, CS3] Texts of a xmlElement

    Thomas B. Nielsen Level 3

      I'm having a little thing here i dont understand. I found the below code on the forum, and have modyfied it very little.


      I use the script to find all xmlElements with a given name, and returning an array of the xmlElements.texts. Problem is, that for autotagged text in cells, xmlElements.texts is all text in the cell, exept for the first character, what am I doing wrong?

       

      Please see the comments to the two alerts in the script.

       

      function getItemsByXmlTag() {
          var xpath = ["//Cell"];
          var xmlItemMatches = getXmlMatches(xpath);
         
          function getXmlMatches(myXPath){
              var myXMLElements = new Array;
              var _items = new Array;
              var myRuleProcessor = app.xmlRuleProcessors.add(myXPath);
              try{
                  var myMatchData = myRuleProcessor.startProcessingRuleSet(app.documents.item(0).xmlElements.item(0));
              while(myMatchData != undefined){
                  var myElement = myMatchData.element;


                  myXMLElements.push(myElement);

       

                 alert(myElement.contents); //Always gives me the text contents

                 alert(myElement.texts[0].contents); // Gives me the same as above, exept for all "autotagged" elements like "Cell". If its a cell containing some text, this alert gives me the text of the cell, but without the first character - what am i missing?


                  _items.push(myElement.texts);

       

                  myMatchData = myRuleProcessor.findNextMatch();
              }
                  myRuleProcessor.endProcessingRuleSet();
                  myRuleProcessor.remove();
                  return _items;
              }
              catch (myError){
                  myRuleProcessor.endProcessingRuleSet();
                  myRuleProcessor.remove();
                  throw myError;
              }
          }
      }