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

我有谷歌结帐沙箱生成的 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" />

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

94275 次浏览

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 ABC1 instead of &:

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 &w as an entity. But entities are always terminated by an ;, thus if the ; is missing you get the error message.

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

<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 &amp replacing the & I was able to save my HTML file.