8 Replies Latest reply on Apr 13, 2015 7:04 AM by Peter Kahrel

    CDATA Error

    KuddRoww Level 1

      This script hangs:


      var xml = []
      var Question  = "Foo"
      xml[xml.length] = """<text><![CDATA[<p>"""+Question+"""<br></p>]]></text>"""


      I was able to get the script to work with the following work around:


      var xml = []
      var questionText = "Foo"
      var left = "<![CDATA[<p>"
      var right = "<br></p>]]"
      var right2 = ">"
      xml[xml.length] = """<text>"""+left+questionText+right+right2+"""</text>"""


      Is there a less 'hacked' way to be able to have the script application pass the CDATA as a string?


      If I comment out the CDATA tag for testing the script would hang. If I split it into two parts (<![CDATA[<p>,<br></p>]]>) it also hangs. I wonder why concatenating the closing portion of the tag as two string variables is allowed?


      Thanks for your time and thoughts spent on this,



        • 1. Re: CDATA Error
          Vamitul Level 4

          works fine on my end, but that is one very very very weird code snippet:

          1) why are you using triple quotes? this is not python?

          2) why use that weird construct xml[xml.length] instead of xml[0] ?

          3) why use an array instead of a native XML object?

          • 2. Re: CDATA Error
            KuddRoww Level 1

            1. I don't want to escape special characters so it was easier to just compose with triple quotes than escape quotes. ie. <generalfeedback format="html"> 2. My understanding is there is two ways to add objects to an array. arr.append(obj) OR arr[arr.length] = obj. As far as I know it's not an obscure style, and if I remember correctly the second method is fractionally quicker. 3. I'm writing the XML to a File at the end of the script. *shrugs* Is there an advantage to writing as a "native XML object"?


            What does 'works fine on your end' mean? The first snippet, second snippet? If the first snippet works on your end then are you using CC 2014? I've tried both ExtendScriptToolkit and InDesign  as targets and both hang.


            Thanks for the gander,

            • 3. Re: CDATA Error
              Loic.Aigon Adobe Community Professional

              Vamitul, KuddRoww,


              I wanted to offer kuddroww a different approach ( mostly E4X ) but as soon as I try to use the CDATA section, it indeed makes the script to hang for ever. I thought of a script until you said you could make it work.


              • 4. Re: CDATA Error
                Justin Putney Level 2

                I get the script hang when using CDATA with E4X as well, Loic. My solution is to run the script from another script.

                • 5. Re: CDATA Error
                  pixxxel schubser Most Valuable Participant


                  this seems to be a bug with CDATA (IMHO since CS5)



                  var xml = [];
                  var Question  = "Foo";
                  xml[xml.length] = "<text><![CDATA[<p>"+Question+"<br></p>]]\></text>";


                  This should do the job.


                  Have fun


                  • 6. Re: CDATA Error
                    Laubender Adobe Community Professional & MVP

                    FWIW — it's maybe related, maybe it's not: I also had some problems with the ESTK, InDesign CS5 and a ![CDATA-error.

                    If I ran a script on an InDesign Table object and tried to read out or to assign its contents value the ESTK always throws an error: "![CDATA"

                    However if I ran the script from InDesign CS5, no error was thrown. That specific error went away with the CS6 version of the ESTK.



                    • 7. Re: CDATA Error
                      Vamitul Level 4

                      ESTK passes the script to Indesign (using BridgeTalk) as a xml object, with the actual javascript code embedded in a CDATA, so it seems that is he root of the problem (the "inner", script embedded CDATA tag is not escaped).


                      However, i just tested again the code using ESTK CC, and both original snippets seem to work just fine.

                      • 8. Re: CDATA Error
                        Peter Kahrel Adobe Community Professional & MVP

                        Various CDATA problems were fixed in the ESTK I think in CS6 (maybe CS5.5).