1 Reply Latest reply on Feb 15, 2011 8:37 AM by BeriliaTubul

    [JS] XML : How to placeXML the content of a specific tag

    BeriliaTubul

      Hi, I'm new to scripting and I can't figure out how to do this :

       

      I need to find the first element with the tag "body" and make a placeXML on it.

      I make a function do find it, but I really don't know what to do after that.

       

      Here is my code :

       

      var tab= new Array();

      var body = findFirstElement(myDocument,"body", tab);

       

      function findFirstElement(elm, tag, tab)

      {

          for (var i = 0; i < elm.xmlElements.length; i++)

          {

              XMLelementName=elm.xmlElements[i].markupTag.name.toString();

              if(XMLelementName==tag)

              {

                  elm.xmlElements[i].select();

                tab.push(elm.xmlElements[i]);

              }

              else {

              findFirstElement(elm.xmlElements[i], tag, tab);

              }

          }

         return tab;

      }

       

      At this point, body is [object XMLElement]

       

      So now, I would like to modify the following code to place body. I think I don't understand very well the structure of the document, but once again, I'm totally new at it.

      myDocument.xmlElements.item(0).xmlElements.item(0).placeXML(myDocument.pages.item(0).textF rames.item(0));

       

      If someone can help me...

        • 1. Re: [JS] XML : How to placeXML the content of a specific tag
          BeriliaTubul Level 1

          Hi,

           

          I finally found out how to do it : it's easy with XML Rules.

           

          Here is my code if someone is interested :

           

          var myRuleSet = new Array (new ShowBody);

          with(myDocument){

          var elements = xmlElements;

          __processRuleSet(elements.item(0), myRuleSet);

          }

           

           

          function ShowBody(){

          this.name = "ShowBody";

          //XPath will match on every XML element in the XML structure.

          this.xpath = "//body";

          // Define the apply function.

          this.apply = function(myElement, myRuleProcessor){

          with(myElement){

          myElement.placeXML(myDocument.pages.item(0).textFrames.item(0));

          }

          return true;

          // Succeeded

          } //End of apply function

          }