2 Replies Latest reply on Oct 12, 2012 10:19 AM by KuddRoww

    flowing XML content into a document

    KuddRoww Level 1

      Right now I use the following workflow for an XML placement. I import the XML with a script from the CS5 Scripting Guide. I pull up the structure panel and I drag and drop the XML root element onto the document, the document automatically adds pages and inserts the content of the XML file. This is exactly what I'd like to be able to do, but with a script. How can I accomplish this? Also what would be the proper term for this sort of thing? I think of it as "reflowing the XML content into the document", but I'm wondering if there's a more accurate term.

       

      Thank-you for an and all help provided.

        • 1. Re: flowing XML content into a document
          absqua Level 4

          Pretty much just this, I think:

           

          var doc = app.activeDocument;
          var frame = doc.masterSpreads[0].textFrames[0].override(doc.pages[0]);
          frame.markup(doc.xmlElements[0]);
          

           

          (Untested.)

           

          Jeff

          • 2. Re: flowing XML content into a document
            KuddRoww Level 1

            So I finished hacking out what I have:

            function placeXML(myDocument){     var txfBounds = [];     txfBounds.push(myDocument.pages[0].bounds[0]+myDocument.marginPreferences.top);     txfBounds.push(myDocument.pages[0].bounds[1]+myDocument.marginPreferences.left);     txfBounds.push(myDocument.pages[0].bounds[2]-myDocument.marginPreferences.bottom);     txfBounds.push(myDocument.pages[0].bounds[3]-myDocument.marginPreferences.right);     var txf = myDocument.pages.item(0).textFrames.add({geometricBounds: txfBounds});     myDocument.xmlElements.item(0).placeXML(txf);     while(txf.overflows)     {         var txf_previous = myDocument.pages[myDocument.pages.length-1].textFrames.item(0);         var pg_next = myDocument.pages.add();         var txfBounds = [];         if(pg_next.side==PageSideOptions.RIGHT_HAND){         txfBounds.push(pg_next.bounds[0]+pg_next.marginPreferences.top);         txfBounds.push(pg_next.bounds[1]+pg_next.marginPreferences.left);         txfBounds.push(pg_next.bounds[2]-pg_next.marginPreferences.bottom);         txfBounds.push(pg_next.bounds[3]-pg_next.marginPreferences.right);         }         if(pg_next.side==PageSideOptions.LEFT_HAND){         txfBounds.push(pg_next.bounds[0]+pg_next.marginPreferences.top);         txfBounds.push(pg_next.bounds[1]+pg_next.marginPreferences.left+2);         txfBounds.push(pg_next.bounds[2]-pg_next.marginPreferences.bottom);         txfBounds.push(pg_next.bounds[3]-pg_next.marginPreferences.right+2);         }         txf = pg_next.textFrames.add({geometricBounds: txfBounds});         txf_previous.nextTextFrame = txf;     }; };

             

             

            And then I read that. Haha I would feel depressed, but at least I learned something.

             

            Thanks for the help, works perfectly!