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

2022-01-10 00:00:00 xml-parsing html xhtml

我有 Google 结帐沙箱生成的 HTML 代码,可以在 HTML 页面中正常工作.当我将相同的代码放在 XHTML 页面中时,它会引发以下异常:

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:

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

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

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

It's referring the request parameter w in the URL in the below src attribute:

<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?

推荐答案

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

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 &:

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

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

& 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.

相关文章