0

I am trying to dynamically create an xml list.. however when I add in cdata tags it give me an error saying tags must be terminated, even though I'm not using those. It seems like it is trying to read the cdata tags as tags.

var addList:XMLList = new XMLList( "" + "" + personName + "" + "" + personTitle + "" + "" + personEducation + "" + "" + personBio + "" + "")

I read somewhere you have to escape characters, but not sure exactly where.

cherouvim
  • 31,725
  • 15
  • 104
  • 153
pfunc
  • 1,305
  • 2
  • 24
  • 52
  • AFAIK you're not supposed to be double quoting the XML. Not sure how you would add in the variables if your not double quoting though... – invertedSpear Feb 08 '10 at 17:13
  • it works fine when I 'm not using cdata tags. I put in single quoting where I could and it still gives me the same error. The quotes aren't the problem, it's the cdata tags. var addList:XMLList = new XMLList( '' ); – pfunc Feb 08 '10 at 17:21
  • @cherouvim - What did you do with that Edit??? it's completely unreadable now. – invertedSpear Feb 08 '10 at 18:25

1 Answers1

2

You're trying to use this string inside the <Script> tag of a MXML document, yes?

Since script tags are defined inside CDATA blocks themselves, ]]> is an invalid character sequence (or rather, it indicates the end of the CDATA, which should be right before the </Script> closing tag.

It's not possible to escape--see this SO question--but in your case you can easily work around it. Either define constants to mark your CDATA section:

var CDBegin:String = "<!" + "[CDATA[";
var CDEnd:String   = "]]" + ">";    

var s:String = "<text>" + CDBegin + myText + CDEnd + "</text>";

or move your XML construction to a pure Actionscript file instead of MXML.

Community
  • 1
  • 1
Michael Brewer-Davis
  • 14,018
  • 5
  • 37
  • 49