【问题标题】:Escape many tags at the same time in XML在 XML 中同时转义多个标签
【发布时间】:2012-03-31 03:45:43
【问题描述】:

我有一个包含 HTML 文档内容的 XML 标记。

<xml-tag>
    <!--
        <p>html document goes here</p>
        <p><span id="important">important html</span></p>
    -->
</xml-tag>

现在,有没有办法在&lt;xml-tag&gt; 的正文中转义整个 html 文档?如果我不对内容进行转义,XML 文档的格式就会不正确,我将无法检索我需要的数据。例如在C#中,如果我想转义整个字符串,我可以将@符号放在字符串前面,在XML中有没有这样做?

【问题讨论】:

    标签: xml escaping character


    【解决方案1】:

    您可以将整个 HTML 部分包装在 CDATA 中:

    <xml-tag>
        <![CDATA[
            <p>html document goes here</p>
            <p><span id="important">important html</span></p>
        ]]
    </xml-tag>
    

    在此处查看有关使用 CDATA 的更多信息:http://www.w3schools.com/xml/xml_cdata.asp

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多