8 Replies Latest reply on Jan 28, 2010 4:28 AM by ramkumar.vp

    Insert XML Image into Table Cell

    Marco Lugli

      Hello all,

      I have an xml file of products including references to the image of each product.

      I'm trying to transform the xml into a table after import into Indesign CS3.


      Here's the general structure of the xml:

        <Image href="file://./00257-00257.tif"/>


      And here's my script:


      function main(){


           var myDocument = app.activeDocument;


          //Add tag elements
          var myRowTag = myDocument.xmlTags.add("row");
          var myCellTag = myDocument.xmlTags.add("cell");
          var myTableTag = myDocument.xmlTags.add("table");

          //Add XML elements.
          var myRootXMLElement = myDocument.xmlElements.item(0);//Root
          var myProducts = myRootXMLElement.xmlElements;

          //Create elements for table
          with(myRootXMLElement){ //First with
              var myTableXML = xmlElements.add(myTableTag);
                  for(var myRowCounter = 0; myRowCounter < myProducts.length -1; myRowCounter++){ //First for


                      var myProducts = myRootXMLElement.xmlElements.item("Product");
                      var myProduct = myProducts[myRowCounter];
                      with(xmlElements.add(myRowTag)){ //Second with
                          var myProductXMLElements = myProduct.xmlElements;
                          for(var myCellCounter = 0; myCellCounter < myProductXMLElements.length; myCellCounter++){ //Second for
                              with(xmlElements.add(myCellTag)){ //Third with
                                  var contents = myProductXMLElements[myCellCounter].contents;


                              } //end of third with
                          } //end of Second for
                      } //end of second with
                  } //end of di First for
              } //end of first with

          //Remove old tags from Structure


          //Create table
          var myTable = myTableXML.convertElementToTable(myRowTag, myCellTag);   



      Here's the result (inside Indesign):




      The problem is I can't insert the image into its cell: any suggestions?