Flash AS2: How to POST CDATA to a server?
-
22-07-2019 - |
Question
I have an XML object that I want to send to my player via HTTP POST. This is all good when using XML.sendAndLoad.
The problem is that when the XML object I generate contains CDATA, the CDATA is stripped out before the POST occurs.
so if I have:
var xml:XML = new XML("<root><tag><![CDATA[hello]]></tag></root>")
when I do a sendAndLoad this is what gets POSTed:
<root><tag>hello</tag></root>
the same occurs when I try to create the XML using XMLDOM methods like createElement, createTextNode, and appendChild.
the AS2 docs say that CDATA is not supported. Is there a workaround for this? I'm thinking that it could be fixed by extending and overriding the XML class, but I haven't found a way to do it yet.
Thanks!
Solution
This is the expected behavior. CDATA is substituted by the XML parser at the time it builds its tree. What is sent is a serialization of the tree, sans the CDATA.
If you want to send raw XML source you have to send it as pure string data.
BTW I fail to see how it can be a problem here, since both are semantically identical, i.e. "<![CDATA[hello]]>" and "hello" give the same string. CDATA is just a quoting syntax, not significant markup. However there can be a problem if the CDATA contains special characters. You will have to quote them properly.