7 Replies Latest reply on Sep 1, 2010 12:35 PM by [Jongware]

    CS5/JS Insert special characters, plural, around XML elements

    Jeremy bowmangraphics Level 2

      If I want to insert a column break after an XML element, I use this:

       

      myXMLElement.insertTextAsContent(SpecialCharacters.COLUMN_BREAK, XMLElementPosition.AFTER_ELEMENT);

       

      But what if I want to insert TWO column breaks?

        • 1. Re: CS5/JS Insert special characters, plural, around XML elements
          [Jongware] Most Valuable Participant

          Repeat the command

           

          AFAIK, SpecialCharacters can only be inserted one at a time.

          1 person found this helpful
          • 2. Re: CS5/JS Insert special characters, plural, around XML elements
            Jeremy bowmangraphics Level 2

            You'd think so, but apparently not:

             

            var myDocument = app.documents.add();

            var myXMLTag = myDocument.xmlTags.add("myTag");

            var myXMLElement = myDocument.xmlElements.item(0).xmlElements.add(myXMLTag);

            myXMLElement.contents = "This is text inside an XML element";

            myXMLElement.insertTextAsContent(SpecialCharacters.COLUMN_BREAK, XMLElementPosition.AFTER_ELEMENT);

            myXMLElement.insertTextAsContent(SpecialCharacters.COLUMN_BREAK, XMLElementPosition.AFTER_ELEMENT);

            • 3. Re: CS5/JS Insert special characters, plural, around XML elements
              [Jongware] Most Valuable Participant

              In your context, this doesn't do anything either:

               

              myXMLElement.insertTextAsContent("wot?", XMLElementPosition.AFTER_ELEMENT);

               

              If you change the position to XMLElementPosition.ELEMENT_END it works as it should -- so, it must be something like "Thou shalt not add something between elements in the structure tree". It kind of makes sense -- there is nothing 'between' elements in the plain XML structure. I didn't try but I bet it does work when you are referring to already placed and tagged text.

              1 person found this helpful
              • 4. Re: CS5/JS Insert special characters, plural, around XML elements
                [Jongware] Most Valuable Participant

                (Grumble.)

                 

                Of course this does do something ...

                 

                var myDocument = app.documents.add();
                var myXMLTag = myDocument.xmlTags.add("myTag");
                var myXMLElement = myDocument.xmlElements.item(0).xmlElements.add(myXMLTag);
                myXMLElement.contents = "This is text inside an XML element";
                myXMLElement.insertTextAsContent(SpecialCharacters.COLUMN_BREAK, XMLElementPosition.AFTER_ELEMENT);
                myDocument.xmlElements.item(0).xmlElements.add(myXMLTag).contents = "Wot?";
                

                 

                I'll give you a "between" but I think I'll stick to my "not-after-the-last".

                • 5. Re: CS5/JS Insert special characters, plural, around XML elements
                  [Jongware] Most Valuable Participant

                  (More grumbling -- (why don't I try before posting)):

                   

                  Oh okay. A further constraint seems to be you can add multiple columns breaks or hard returns, but it's kind of unpredictable what gets added.

                   

                  This

                   

                  myXMLElement.insertTextAsContent("\r", XMLElementPosition.AFTER_ELEMENT);
                  myXMLElement.insertTextAsContent(SpecialCharacters.COLUMN_BREAK, XMLElementPosition.AFTER_ELEMENT);

                  adds a hard return and a column break (which end up in reverse order -- at least that works). This

                   

                  myXMLElement.insertTextAsContent(SpecialCharacters.COLUMN_BREAK, XMLElementPosition.AFTER_ELEMENT);
                  myXMLElement.insertTextAsContent("\r", XMLElementPosition.AFTER_ELEMENT);

                  only adds a column break.

                   

                  It would appear there is only one hard return allowed between elements -- try it with inserting a "\r" twice. That might just be "logical" because you cannot have real blank lines inside XML.

                  Perhaps it's the internal translation of Hard Return Column Break that messes things up in the above case.

                  • 6. Re: CS5/JS Insert special characters, plural, around XML elements
                    Jeremy bowmangraphics Level 2

                    By Grabthar's Hammer, you've got it! Never give up -- never surrender!

                     

                    I'm going to use

                     

                     

                    myXMLElement.insertTextAsContent(SpecialCharacters.PAGE_BREAK,  XMLElementPosition.AFTER_ELEMENT);

                    myXMLElement.insertTextAsContent(SpecialCharacters.COLUMN_BREAK, XMLElementPosition.AFTER_ELEMENT);

                     

                     

                    ...which puts a column break followed by a page break, which suits my purposes just as well as two column breaks.

                     

                    I need them after the element rather than at the end of the element, because they're part of an XML "template" (if that's the word) that imported XML will flow into (with cloning). The contents of the equivalent non-empty incoming element will simply replace the contents that formerly contained the breaks, when what I really want is an empty column (apart from the second column break or page break), which the user can drag other XML elements into using the Structure Panel.

                     

                    If that makes any sense.

                     

                    EDIT: I forgot to say thanks: Thanks!

                    • 7. Re: CS5/JS Insert special characters, plural, around XML elements
                      [Jongware] Most Valuable Participant

                      <Computer>You're welcome.</Computer>

                      <Gwen>The computer says you're welcome.</Gwen>

                       

                      It's funny inserting two different breaks works as well...

                      (Perhaps not so funny for the Adobe programmer who messed it up -- he seemed to have missed this )