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

Inline XML with CDATA problem

New Here ,
Aug 25, 2008 Aug 25, 2008
Hi everyone,

I'm trying to include some JavaScript (JSON 2, to be precise) in with some ActionScript 3 classes. I'm using the inline XML method (E4X) of declaring the data. It looks like this:

public static var JSON_2:XML = <data><![CDATA[
if (!this.JSON) {
JSON = function () {
function f(n) {
return n < 10 ? '0' + n : n;
}
Date.prototype.toJSON = function (key) {
return this.getUTCFullYear() + '-' +
f(this.getUTCMonth() + 1) + '-' +
f(this.getUTCDate()) + 'T' +
f(this.getUTCHours()) + ':' +
f(this.getUTCMinutes()) + ':' +
f(this.getUTCSeconds()) + 'Z';
};
String.prototype.toJSON =
Number.prototype.toJSON =
Boolean.prototype.toJSON = function (key) {
return this.valueOf();
};

var cx = /[\u0000

]]></data>

Actually, this is only about a quarter of what I need to include but this is where it breaks down. Right after the second slash in the last line, Flash reports:

TypeError: Error #1091: XML parser failure: Unterminated CDATA section.

In fact, as you can see this is a perfectly valid CDATA section and isn't being terminated anywhere (there is no instance of "]]>" anywhere in the data). Unfortunately, Flash doesn't think so and seems to think that the backslash is an XML node directive.

Does anyone have an idea of how to effectively deal with this? The JSON source code has *many* backslashes so not having to convert them would be *very* useful.

Many thanks for all your suggestions,
Patrick
TOPICS
ActionScript
1.6K
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
New Here ,
Aug 25, 2008 Aug 25, 2008
LATEST
I've *kind* of solved the problem...replacing each backslash ("\") with a double backslash ("\\"). At least this has removed the compiler error. However, this would suggest that the CDATA section is actually being interpreted by Flash, which is something it isn't supposed to do...or did I misunderstand how this works?
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