Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

CDATA Error

Contributor ,
Apr 09, 2015 Apr 09, 2015

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,

Kurtis

TOPICS
Scripting
2.1K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Apr 09, 2015 Apr 09, 2015

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?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Apr 09, 2015 Apr 09, 2015

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,

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
People's Champ ,
Apr 09, 2015 Apr 09, 2015

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.


Loic

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Enthusiast ,
Apr 09, 2015 Apr 09, 2015

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 10, 2015 Apr 10, 2015

KuddRoww‌,

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

Try:

var xml = [];

var Question  = "Foo";

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

This should do the job.

Have fun

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 12, 2015 Apr 12, 2015

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.

Uwe

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Apr 12, 2015 Apr 12, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Apr 13, 2015 Apr 13, 2015
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines