2 Replies Latest reply on Sep 5, 2012 2:07 AM by Hachy707

    JS : 2 XML nodes in the same textFrame with 2 different style

    Hachy707 Level 1

      Hello,

       

      I am French and my English is poor. Sorry in advance if anything is unclear.

       

      I have an XML with 2 nodes. I would fill a texteFrame with these 2 nodes following AND with 2 different style. Here is my current code:

       

      var myRootXMLElement = myDocument.xmlElements.item(0).xmlElements.item(0).xmlElements.item(1).xmlElements.item(3 );

      var myXMLElementA = myRootXMLElement.xmlElements.item(1); //node 1 (a firstname)

      var myXMLElementB =  myRootXMLElement.xmlElements.item(2);//node 2 (a name)

       

       

      myParagraphStyle = myDocument.paragraphStyles.item("al_qu_auteur"); // paragraphStyles

      myCharacterStyle1 = myDocument.characterStyles.item("al_qu_prenom_auteur"); // characterStyles 1 for the firstname

      myCharacterStyle2 = myDocument.characterStyles.item("al_qu_nom_auteur"); // characterStyles 1 for the name

       

      var myTextFrame3 = myPage.textFrames.add({geometricBounds:[156.5, 163, 170, 377.25]});

      myTextFrame3.placeXML(myXMLElementA);

       

      How add "myXMLElementA" in "myTextFrame3"?

       

       

      I try an other code:

      var myRootXMLElement = myDocument.xmlElements.item(0).xmlElements.item(0).xmlElements.item(1).xmlElements.item(3 );

      var myXMLElementA = myRootXMLElement.xmlElements.item(1);

      var myXMLElementB =  myRootXMLElement.xmlElements.item(2);

       

       

      myParagraphStyle = myDocument.paragraphStyles.item("al_qu_auteur");

      myCharacterStyle1 = myDocument.characterStyles.item("al_qu_prenom_auteur");

      myCharacterStyle2 = myDocument.characterStyles.item("al_qu_nom_auteur");

       

       

      var myTextFrame3 = myPage.textFrames.add({geometricBounds:[156.5, 163, 170, 377.25]});

      myTextFrame3.contents = myXMLElementA.contents + " " + myXMLElementB.contents ;

      myTextFrame3.parentStory.texts.item(0).applyParagraphStyle(myParagraphStyle, true);

       

      But how add 2 CharacterStyle?

       

       

      Thank you in advance

        • 1. Re: JS : 2 XML nodes in the same textFrame with 2 different style
          benjaminmueller_burda

          HI,

           

          try this

           

          var myPage = app.activeDocument;

           

          var rootElement = myPage.xmlElements.item(0);

           

          var theTextFrameXML = rootElement.xmlElements.add("textframe");

          var theTextFrame = myPage.textFrames.add({geometricBounds:[156.5, 163, 170, 377.25]});

           

          theTextFrame.placeXML(theTextFrameXML);

           

          var firstCharacterStyle = myPage.characterStyles.itemByName("al_qu_prenom_auteur");

          theTextFrameXML.insertionPoints.item(-1).applyCharacterStyle(firstCharacterStyle);

          theTextFrameXML.insertionPoints.item(-1).contents = "First Name";

           

          space = theTextFrameXML.insertionPoints.item(-1).contents = " ";

           

          var secondCharacterStyle = myPage.characterStyles.itemByName("al_qu_nom_auteur");

          theTextFrameXML.insertionPoints.item(-1).applyCharacterStyle(secondCharacterStyle);

          theTextFrameXML.insertionPoints.item(-1).contents = "Last Name";

           

          applying 2 character style to one character (word etc.) is not possible.

           

          regards

           

          b.