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

查看:33
本文介绍了在另一个 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 hope I was clear enough.

推荐答案

您可以转义 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天全站免登陆