android - 错误!在 strings.xml 资源 Android 中使用 CDATA

标签 android cdata

我的 Android 项目中有一个字符串资源,我正在使用 CDATA 部分将我的字符串嵌入到 XML 中:

<string name="ackng"><![CDATA[
    <html>
<body>
    <h1>Acknowledgements</h1> 
    <p>
        Senator  Paul  Wellstone's  book,  the  Conscience  of  a  Liberal:  Reclaiming  the
        compassionate agenda was an inspiration and an affirmation that you can be truthful
        and  honest  as  a  politician,  and  compassionate  and  people-centred  as  a  representative.
        And  as  President  Bill  Clinton  affirmed  as  he  addressed  the  joint  session  of  the
        National  Assembly  on  26th  August,  2000,  thus:
        “Every  nation  that  has  struggled  to  build  democracy  has  found  that  success
        depends on leaders  who believe government exists to  serve people, not the
        other  way  around.”
    </p>
    <p>
        Paul  Wellstone's  book  was  my  inspiration  for  the  launching  of  the  compassionate
        agenda  in  February  2002.  Clinton's  speech  affirmed  my  convictions  regarding  the
        sanctity of the democratic mandate to serve the people. I acknowledge the clarity of
        their  focus  and  the  inspiration  their  works  continue  to  provide.
    </p>
</body></html>]]></string>

但 eclispe 返回此错误:

[2013-02-18 00:11:05 - MyPA] C:\Users\Daniel\workspace\MyPA\res\values\strings.xml:191: error: Apostrophe not preceded by \ (in  <html>

最佳答案

撇号 (') 必须使用 \ 进行转义。尝试在整个字符串的内容中使用 \' 而不是 '

此外,您需要在以下部分使用 \" 转义 ":

“Every  nation  that  has  struggled  to  build  democracy  has  found  that  success
depends on leaders  who believe government exists to  serve people, not the
other  way  around.”

关于android - 错误!在 strings.xml 资源 Android 中使用 CDATA,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14927326/

相关文章:

javascript - 尝试在脚本标记中动态添加 CDATA 时出现语法错误

java - 检查API版本

java - 我们可以将 CDATA 嵌入到 xml 中的名称值对的纯字符串中吗?

postgresql - 如何使用 PostgreSQL 从 xml 检索 C DATA 值

android - JSONObject 的大尺寸 JSON 字符串不起作用

perl - 如何按节点类型获取 XML::LibXML 中的子节点?

java - 如何为 &lt;![CDATA[]]> 解析 XML

Android MediaStore.Images.Media.insertImage 只有在使用相机应用拍照后才能在 KitKat 上运行

android - 短信已发送ContentObserver

Android - 背景图像的最佳分辨率?