开发者

flex creating xmllist with cdata

开发者 https://www.devze.com 2022-12-19 18:47 出处:网络
I am trying to dynamically create an xml list.. however when I add in cdata tags it give me an error sayingtags must be terminated, even though I\'m not using those. It seems like it is trying to read

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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消