3 Replies Latest reply on Sep 22, 2009 1:25 AM by Kasyan Servetsky

    XML Attribute to XML element

    SB Masthan

      Dear All,

       

      I have tried to convert some XML attributes in "pageinfo" tag to XML element with the following code, but it is not working. Kindly help.

       

      var myDoc = app.activeDocument;
      var myElement=myDoc.xmlElements[0];
      var myXMLElements = new Array;

      myXMLElements = myGetXMLElements("//pageinfo");

       

      if(myXMLElements.length > 0){
      for(var myCounter = 0; myCounter <= myXMLElements.length-1; myCounter++){
      var myXMLElement = myXMLElements[myCounter];


      myXMLElement.xmlAttributes.item(0).convertToElement(LocationOptions.atBeginning, myDoc.xmlTags.item("link"));
            
             }
      }

       


      function myGetXMLElements(myXPath){
      var myXMLElements = 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);
      myMatchData = myRuleProcessor.findNextMatch();
      }
      myRuleProcessor.endProcessingRuleSet();
      myRuleProcessor.remove();
      return myXMLElements;
      }
      catch (myError){
      myRuleProcessor.endProcessingRuleSet();
      myRuleProcessor.remove();
      throw myError;
      }
      }

       

      regards

      Masthan