4 Replies Latest reply on Feb 16, 2012 1:11 AM by Jayflux

    From XML (import) for each record automatic new page creation?

    indesignstarter

      Hello,

       

      I'm playing around with XML.

      Can someone tell me where to look and help me?

      I load variable data via XML.

       

      Example content xml:

           

      <pages>
           <page>
               <id>1</id>
               <article>title page 1</article>
               <info>Info page 1</info>
               <price>price page 1</price>
           </page>
           <page>
               <id>2</id>
               <article>title page 2</article>
               <info>Info page 2</info>
               <price>price page 2</price>
           </page>
           <page>
               <id>3</id>
               <article>title page 3</article>
               <info>Info page 3</info>
               <price>price page 3</price>
           </page>
      </pages>

       

       

      I have 1 page classified (ie 3 text boxes). The idea is that for each record in the xml (in this case 1, 2 and 3) a new page is created (Qua layout identical to the page that I had prepared, but with the corresponding data in each box)

      How do I do this?

       

      Thanks!

        • 1. Re: From XML (import) for each record automatic new page creation?
          Jayflux

          Hi indesignstarter

           

          I am trying to do exactly the same thing!

          It looks like some javascripting needs to be involved but so far I've yet to get even close to achieving this.

           

          Please reply if you find out or have any ideas.

          • 2. Re: From XML (import) for each record automatic new page creation?
            Nigel Chapman

            If you need to keep the three parts of your page in separate text frames, you are probably out of luck.

             

            I can't tell from your question whether you know how to tag frames and import XML content into them. If you don't, the manual is fairly clear on it. However, it states more than once that "InDesign flows merged XML content into existing frames only."  That means that it won't add frames or pages for you -- you can only load XML into tagged frames on the first page and will have to add extra ones by hand.

             

            If you could rework your design so that all the elements could be accommodated in a single text frame, using paragraph styles to keep them apart, you could just import the XML and map tags to styles, then drag it into a frame on the first pages. If your article style was set to start in a new frame,  everything but the first would go into overset text, which you could deal with in the usual way -- shift-click on the in port of a new frame and InDesign will add the pages you need.

            • 3. Re: From XML (import) for each record automatic new page creation?
              Jayflux Level 1

              is it not possible to create some sort of loop within Javascript?

               

              Pull all the page elements into an array, then create a new page for each one and inser the frames in that page.

              • 4. Re: From XML (import) for each record automatic new page creation?
                Jayflux Level 1

                I've managed to do this properly now.

                 

                I mainly followed this:

                http://www.loicaigon.com/blog/?p=1050

                 

                A: Recursivity is the example I used then i slightly re-wrote it.

                 

                First i use xPath to find the <page> elements.

                Then I just ran a loop and for each page element i run myDocument.pages.add();

                and when i get round to the next instance of the loop I change the page the placeXML prints to using pages.item(i).

                 

                Working great here, now I just need to work out how to pull XML from a url which seems impossible.