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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6483807/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 09:15:57  来源:igfitidea点击:

The reference to entity "foo" must end with the ';' delimiter

htmlxml-parsingxhtml

提问by Adnan

I have Google checkout sandbox generated HTML code which works fine in HTML page. When I put the same code in XHTML page, it throws the below exception:

我有谷歌结账沙箱生成的 HTML 代码,它在 HTML 页面中运行良好。当我在 XHTML 页面中放置相同的代码时,它会抛出以下异常:

the reference to entity "w" must end with the ';' delimiter

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

It's referring the request parameter win the URL in the below srcattribute:

w在以下src属性中引用URL 中的请求参数:

<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" />

How is this caused and how can I solve it?

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

回答by Floern

The ampersand &is a special character in HTML and XML. If you want to use it as a normal character, you have to encode it correctly. Write &amp;instead of &:

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

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

&denotes the start of an encoded entity, such as &lt;for <, or &amp;for &. In your case the parser tries to interpret &was an entity. But entities are always terminated by an ;, thus if the ;is missing you get the error message.

&表示编码实体的开始,例如&lt;for<&amp;for &。在您的情况下,解析器尝试将其解释&w为实体。但是实体总是以 终止;,因此如果;缺少 ,您会收到错误消息。

回答by cyberabel

This worked on my side, when using search iq's installation code on my Blogger blog's HTML file:

在我的 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);
})();

Gave me error here: &engineKey, after adding &ampreplacing the &I was able to save my HTML file. Knowledge appreciated. ^_^

在这里给我错误:&engineKey,在添加&替换& 后,我能够保存我的 HTML 文件。知识赞赏。^_^