在另一个CDATA中使用CDATA [英] Using CDATA inside another CDATA

查看:83
本文介绍了在另一个CDATA中使用CDATA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到这种困难的情况,我需要在另一个CDATA标记内使用CDATA标记。情况很容易解释。

I have this difficult situation where I need to use the CDATA tags inside another CDATA tags. The situation is simple to explain though.

我有以下内容:

<edit>
<![CDATA[
<script type="text/javascript">
<![CDATA[
    window.onload = function() 
    {
        document.getElementById('block').onclick = function() 
        {
            this.onclick = '';
            this.value = '{LA_SEND_CONFIRM}';
            this.className = this.className.replace('button1','');
            document.getElementById('replacement').value = '{LA_BLOCK_CODE}';
        }
    }
]]>
</script>
]]>
</edit>

我也需要将Javascript包装在CDATA中以显示目的,因此,当我打开该XML文件时,它会正确显示,并且Javascript代码位于这些CDATA标记内。它们在XML文件本身中没有实际含义。

I need to wrap my Javascript inside CDATA too for showing purposes, so when I open that XML file, it shows up properly and the Javascript code is inside those CDATA tags. They have no real meaning inside the XML file itself.

您已经知道,上面的代码会给我一个XML解析错误,因为嵌套CDATA无效。有没有办法逃避]]> 以便向用户显示这些括号?

As you already know, the code above would give me an XML parsing error, as nesting CDATA wouldn't work. Is there a way to escape the ]]> so I can show those brackets to my users?

I希望我足够清楚。

推荐答案

您可以逃避]]> 将CDATA部分中的子字符串替换为:

You can escape ]]> substring in CDATA section by replacing it with:

]]]]><![CDATA[>

...行。有了这个,您将使] 成为一个CDATA节的一部分,而> -成为另一个,开始就在前一个结束时。

... line. With this you'll make ]] a part of one CDATA section, and > - of another, that starts right when the preceding one ends.

这篇关于在另一个CDATA中使用CDATA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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