【问题标题】:The reference to entity "foo" must end with the ';' delimiter对实体“foo”的引用必须以“;”结尾分隔符
【发布时间】:2011-09-22 22:50:24
【问题描述】:

我有 Google 结帐沙盒生成的 HTML 代码,它在 HTML 页面中运行良好。当我将相同的代码放在 XHTML 页面中时,它会引发以下异常:

对实体“w”的引用必须以“;”结尾分隔符

它在下面的src属性中引用了URL中的请求参数w

<input type="image" name="Google Checkout" alt="Fast checkout through Google"
    src="http://sandbox.google.com/checkout/buttons/checkout.gif?merchant_id=211512493599623&w=180&h=46&style=white&variant=text&loc=en_US"
    height="46" width="180" />

这是怎么引起的,我该如何解决?

【问题讨论】:

    标签: html xml-parsing xhtml


    【解决方案1】:

    & 符号&amp;amp; 是 HTML 和 XML 中的特殊字符。如果要将其用作普通字符,则必须对其进行正确编码。 &amp;amp;而不是&amp;amp;

    src="...9623&amp;w=180&amp;h=46&amp;style=white&amp;variant=text&amp;loc=en_US"
    

    &amp;amp; 表示编码实体的开始,例如&amp;lt; 表示&lt;,或&amp;amp; 表示&amp;amp;。在您的情况下,解析器尝试将 &amp;w 解释为一个实体。但是实体总是由; 终止,因此如果; 丢失,您会收到错误消息。

    【讨论】:

    • 简单直接!我居然用这个答案解决了Android SIMPLE xml库的一个问题哈哈...
    • 我只是用它来解决 Google 电子表格 API 的问题 =)
    • 我可以在不更改 XML 的情况下修复它吗?
    【解决方案2】:

    当在我的 Blogger 博客的 HTML 文件上使用 search iq 的安装代码时,这对我有用:

    <script type="text/javascript">
    (function () {
        window.siqConfig = {
            engineKey: "6e14b3aacb2b93b658f8729adec0c030",
            forceLoadSettings: false        // change false to true if search box on your site is adding dynamically
        };
        window.siqConfig.baseUrl = "//pub.searchiq.co/";
        var script = document.createElement("SCRIPT");
        script.src = window.siqConfig.baseUrl + '/js/container/siq-container-2.js?cb=' + (Math.floor(Math.random()*999999)) + '&engineKey=' + siqConfig.engineKey;
        script.id = "siq-container";
        document.getElementsByTagName("HEAD")[0].appendChild(script);
    })();
    

    这里给了我错误:&engineKey,在添加 &amp 替换 & 后,我能够保存我的 HTML 文件。

    【讨论】:

      猜你喜欢
      • 2011-07-05
      • 2014-05-26
      • 2010-12-29
      • 2020-07-14
      • 1970-01-01
      • 2012-12-16
      • 2019-10-04
      • 2012-01-31
      相关资源
      最近更新 更多