views:

927

answers:

1

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!

A: 

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.

fbonnet
problem is that the script on the server (i didn't build it) is looking for CDATA. How can I send RAW XML source? I can'y do it with LoadVars since that attaches a var name and that's another thing that the server-side script won't allow.
nerdabilly
The server script is at fault here. Unfortunately I don't see how it can be worked around.As a last resort, try to escape the CDATA delimiters, e.g. ">![CDATA[hello]]<", or setting xml.contentType to 'text/xml'.
fbonnet
Oops I meant <![CDATA[hello]]>
fbonnet