Skip to main content
Inspiring
January 27, 2010
Question

Insert XML Image into Table Cell

  • January 27, 2010
  • 2 replies
  • 2753 views

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:


<Root>
<Product>
  <Image href="file://./00257-00257.tif"/>
  <Code>00257</Code>
  <Price>126,00</Price>
</Product>
</Root>

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);
        with(myTableXML){
           
            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
    myProducts.remove();

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

main();

Here's the result (inside Indesign):

<Root>
  <table>
   <cell></cell>
   <cell>00257</cell>
   <cell>126.00</cell>
  </table>
</Root>

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

Thanks

This topic has been closed for replies.

2 replies

ramkumar_vp
Inspiring
January 28, 2010

Hi Marco Lugli,


In the Product XML: Code & Price are contents but the Image name is an attribute to the Image tag.


So before you doing all the process in script convert the "href" attribute to content in "Image tag".


Regards,

Ramkumar .P

Robert at ID-Tasker
Legend
January 28, 2010

ramkumar.vp wrote:

Could you please stop using blue highlighting ?

robin

www.adobescripts.com

ramkumar_vp
Inspiring
January 28, 2010

Hi Robin,


May I know the reason???


Regards,

Ramkumar .P



Robert at ID-Tasker
Legend
January 28, 2010

Marco Lugli wrote:

[...]

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

How you are trying to do this ?

robin

www.adobescripts.co.uk