Flash AS2:如何将CDATA发布到服务器? [英] Flash AS2: How to POST CDATA to a server?

查看:145
本文介绍了Flash AS2:如何将CDATA发布到服务器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个XML对象,我想通过HTTP POST发送给我的播放器。使用XML.sendAndLoad时,这是很好的。

问题在于,当我生成的XML对象包含CDATA时,CDATA在POST发生之前被除去。



所以如果我有:

pre $ var $ xml:XML = new XML(< root>< tag><![CDATA [hello]]>< / tag>< / root>)

当我做一个sendAndLoad这是什么得到张贴:

 <根><标记>你好< /标签>< /根> 

当我尝试使用XMLDOM方法(如createElement,createTextNode和appendChild)创建XML时,会发生同样的情况。

AS2文件说不支持CDATA。有没有解决方法?我认为可以通过扩展和重写XML类来解决这个问题,但是我还没有找到办法。



谢谢!

解决方案

这是预期的行为。 CDATA在构建树时由XML解析器替代。发送的内容是树的序列化,不包含CDATA。

如果要发送原始XML源,则必须将其作为纯字符串数据发送。



由于两者在语义上是相同的,即<![CDATA [hello]]>,所以我没有看到它在这里如何成为问题。和你好给相同的字符串。 CDATA只是一个引用语法,不是重要的标记。但是,如果CDATA包含特殊字符,可能会出现问题。你将不得不正确引用他们。


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!

解决方案

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.

这篇关于Flash AS2:如何将CDATA发布到服务器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆