标签云

微信群

扫码加入我们

WeChat QR Code

Basically I need to define a node name and its CDATA content using variables.

var nodeName:String = "tag";
var nodeValue:String = "<non-escaped-content>";

Naively I thought this would work :

var xml:XML = <doc><{nodeName}><![CDATA[{nodeValue}]]></{nodeName}>

Outputs :

<doc><tag><![CDATA[{nodeValue}]]></tag></doc>

In a previous version of the script designed for FP9 I bypassed the problem by using :

new XMLNode( XMLNodeType.XMLNodeType.CDATA_NODE, nodeValue ); // ...

but this doesn't seem to work in FP10, and I have the feeling the method is somehow depreciated anyway.

Anyone an elegant solution for this ?


answer updated ... greetz

2018年07月18日10分16秒

Hey, thanks. The reason why I want CDATA is that the method is used to log strings including XML, where a "&lt;" is very different than a "<" of course ... Unfortunately the second solution will convert the tags of the CDATA to "&lt;[CDATA[ ]]&gt;" ignoring the whole signification of the CDATA () :( Did you actually make the 3rd solution work ? This used to work in FP9 but gives me a runtime error in FP10 ?

2018年07月17日10分16秒

I'm not getting the cdata helper function to compile in Flex SDK 3.X anything.

1970年01月01日00分03秒

taudep: what errors are you getting?

2018年07月17日10分16秒

I'm getting mxml compiler error: "Parse error at '\");\n\t\t}\n\n\n\t\....return new XML("<![CDATA[" + data + "]]>");" I added a compilable implementation of the cdata function below.

1970年01月01日00分03秒

this method works good for all case but what if my data is ']]>' i'm getting Error "The markup in the document following the root element must be well-formed." while converting to xml. is there any other way to fix it ?

2018年07月18日10分16秒