1 Reply Latest reply on Nov 16, 2015 5:32 AM by Loic.Aigon

    XML code ends up in 1 text box rather than separate text boxes


      I'm trying to put some XML-based tables into separate text boxes, i.e., one table per page.

      My code (simplified version is below) works except that it puts all 3 tables into the text box on page 3 rather than table 1 into the text box on page 1, table 2 into the text box on page 2, and table 3 into the text box on page 3.


      I have to assume that there is just one little thing I'm missing, but after struggling for a couple of days revising my code multiple times, I thought it was time to ask for help.

      Any hint as to what needs to be changed?






      Function main()

        Set myInDesign = CreateObject("InDesign.Application")

        mySetup myInDesign


        Do Until i>2 

          i = i + 1

          myXMLFilePathName = "c:\XMLTable" & i & ".xml"

        myImportXML myInDesign, i, myXMLFilePathName


      End Function


      Function mySetup(myInDesign)


      End Function



      Function mySetupDoc(myInDesign)

        Set myDocument = myInDesign.Documents.Item(1)

        With myDocument.DocumentPreferences

        .PageHeight = "800pt"

        .PageWidth = "600pt"

        .PageOrientation = idPageOrientation.idPortrait

        .PagesPerDocument = 3

        End With

      End Function



      Function myImportXML(myInDesign, i, myXMLFilePathName)

        Set myDocument = myInDesign.Documents.Item(1)

        Set myPage = myDocument.Pages.Item(i)

        myDocument.ImportXML myXMLFilePathName

        Set myRootXMLElement = myDocument.XMLElements.Item(1)

          set myTextFrame = myDocument.Pages.Item(i).TextFrames.Add()

          myTextFrame.GeometricBounds = Array ("0.5i", "0.5i", "10.5i", "8i")

        myRootXMLElement.PlaceXML myTextFrame

      End Function


        • 1. Re: XML code ends up in 1 text box rather than separate text boxes
          Loic.Aigon Adobe Community Professional



          It's likely an issue with a reference but I wouldn't say for VB. Here is some attempt in JS:


          var main = function(){
            var count = 3, tf;
            var fo = Folder.desktop;
            var xf, root, tag, xe;
            var doc = app.documents.add();
            doc.documentPreferences.pagesPerDocument = count;
            root = doc.xmlElements[0];
            tag = doc.xmlTags.item("tf");
            !tag.isValid && tag = doc.xmlTags.add("tf");
            while ( count-- ) {
            xf = File ( fo+"/table"+(count+1)+".xml" );
            if ( xf.exists ) {
            tf = doc.pages[count].textFrames.add();
            xe = root.xmlElements.add(tag);
            xe.importXML ( xf );
            tf.placeXML ( xe );