3 Replies Latest reply on Aug 31, 2012 7:53 AM by beh_gras_beh

    XML to textframe

    beh_gras_beh Level 1

      Dear people,

       

      I have a XML structure like this.

       

      <item01>
           <item02>data</item02>
           <item03>data</item03>
           <item04>data</item04>
      </item01>
      
      

       

      When I drag "item01" to Indesign from the XML structure everthing is beeing placed incide the <item01> frame.

       

      Is it possible trough scripting that <item02>, <item03>, <item04> is beeing cut and paste in to new textframes inside <item01>?

       

      Greetings!

        • 1. Re: XML to textframe
          vDeepak Level 1

          Hi beh_gras_beh,

           

          If the textFrames you are using are linked frames, then you can just use SpecialCharacters.FRAME_BREAK after each xml elements.

           

          otherwise use.....

           

          var rootElement = app.activeDocument.xmlElements.item(0);

           

          for(var cnt=0; cnt<rootElement.xmlElements.length; cnt++) {

                  var childElement = rootElement.xmlElements.item(cnt);

                  var tFrame = app.activeDocument.textFrames.add();

                  if(tFrame==null)

                      break;

                  tFrame.placeXML(childElement);

          }

           

           

           

          Thanks,

          Deepak.

          1 person found this helpful
          • 2. Re: XML to textframe
            beh_gras_beh Level 1

            Yeah!

             

            That's going the right direction!

             

            Only the script is creating a textframe of the root element <item01>.

            <item02>, <item03> and <item04> are not in a textframe is that possible too?

             

            I thought textframes inside textframes are called inline textrames right? (native language is not English )

             

            Thank you very, very much for the help!

            • 3. Re: XML to textframe
              beh_gras_beh Level 1

              Solved!

               

               

              var mydoc = app.activeDocument;
              var rootElement = mydoc.xmlElements.item(0);
              var linkElementList = rootElement.evaluateXPathExpression("//item01/item02");
              for(var lp=linkElementList.length-1; lp>=0; lp--){
                      var myElement = linkElementList[lp];
                              var myTextframe = myElement.placeIntoInlineFrame(["21p9","5p"]);
                  }
              
              var mydoc = app.activeDocument;
              var rootElement = mydoc.xmlElements.item(0);
              var linkElementList = rootElement.evaluateXPathExpression("//item01/item03");
              for(var lp=linkElementList.length-1; lp>=0; lp--){
                      var myElement = linkElementList[lp];
                              var myTextframe = myElement.placeIntoInlineFrame(["21p9","5p"]);
                  }
              alert("Proces Completed");