6 Replies Latest reply on Mar 8, 2017 6:12 AM by bastieneichenberger

    Build XML structure by scripting

    bastieneichenberger Level 1

      Hi everybody,

       

      I'm writting here regarding a project using XML and ExtendScript.

      I have a big XML file to import in InDesign.

      The InDesign layout is pretty simple (title, content).

       

      I'm looking for a way to write a script with the following steps:

      By hands

      - import the XML file into a 1 page document

      - make the correct structure > link the text frame with the content of the first node of the XML file

       

      By Scripting

      - duplicate the page 1 of the document. (each page correspond to a new XML node)

      - one the page 2 to n, link the text frame with the content of the current node (content 1, content2, content3)

      - I will use the function placeXML(textframe) to build the correct stucture

       

       

       

      Does anyone know if this is a good start?

      I'm confortable with ExtendScript but I'm not sure if there is a better way to build the XML structure?

      Is it possible to get the element like a textframe by name to avoid errors?

       

      Thank you in advance for your help.

        • 1. Re: Build XML structure by scripting
          Kasyan Servetsky Level 5

          You don't need a script for this: use the 'clone repeating text elements' option in the import xml options dialog box.

          Check out the 'work with repeating data' section in indesign help.

          • 2. Re: Build XML structure by scripting
            bastieneichenberger Level 1

            Hi,

             

            Thank you for your message… I'm not sure I'm doing this correctly…
            I tried to import this XML with clone repeating text elements.

             

            It works well but only for the first page. In this project, I will have 300 pages.
            Those pages only contains 1 title and an adresse.

            So during the import InDesign must duplicate the current page with the the layout and merge XML tag with the second row of the database.

             

            So I still need a script to duplicate the master page xxx times. Link all xml fields with the correct text frame?

             

             

            See my capture below.

            Capture d’écran 2017-03-08 à 08.17.21.png

             

            Thank you very much for your advices

             

            P.-S. I found a video here that explain how to do this (IDUG Berlin#31 – InDesign & XML - YouTube ) see at the 43 minutes.
            I guess it is a good way for simple layout. How to do if I need more blocs? If I have multiples stories?

            • 3. Re: Build XML structure by scripting
              Stefan Rakete Level 2

              Hi Bastien,

               

              this is a feasible way you are going, except I would:

               

              1. Add a scripting label to each textframe on the first page, then

              2. Import the XML, then

              3. Duplicate the first page according the the number of nodes in the XML, then

              4. Link each XML node the the corresponding textframe on the page (finding it with the scripting label)

               

              Thanks  stefan

              • 4. Re: Build XML structure by scripting
                Kasyan Servetsky Level 5

                Hi,

                 

                I don't understand German so can't figure out what's going on there.

                 

                I read how to do this in Designer's Guide to Adobe InDesign and XML by James Maivald. But it was a few years ago and I don't remember how I did it since I don't use it in my everyday practice. And I can't find the book and my exercise files on my new computer: I must left them on my old one. But I remember he explained with an example how to clone repeating elements and used no scripts in his book,

                 

                — Kas

                • 5. Re: Build XML structure by scripting
                  Kasyan Servetsky Level 5

                  Well, I've finally found the book and the samples.

                  Here are a couple of screenshots illustrating the approach:

                  Before — a template containing only one page with one xml-element placed.

                  08-03-2017 15-36-47.png

                  After — after importing an xml-file which has identical structure, more pages are inserted (235 in total) and variable data are added to each page. Note: each page has a different dog picture, breed. etc. InDesign does all this automatically: no script was used.

                  08-03-2017 15-38-33.png

                  Are you interested in this or still stick to the idea of doing this by script?

                   

                  — Kas

                  • 6. Re: Build XML structure by scripting
                    bastieneichenberger Level 1

                    Hi,

                     

                    Thank you very much for your help…

                    I still interested, I personally prefer your approach…

                     

                     

                    Is it possible to have your sources files (XML and InDesign)?
                    I the video posted before the process is probably the same but your document seems to be closed from mine.In the example that I have, the author only has one text frame…

                     

                    Thank you for your comments again.
                    Best,
                    Bastien