Flash AS2: How to POST CDATA to a server?

天涯浪子 提交于 2019-12-08 06:40:27

问题


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!


回答1:


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.



来源:https://stackoverflow.com/questions/439747/flash-as2-how-to-post-cdata-to-a-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!