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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14112318/
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 04:39:53  来源:igfitidea点击:

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

htmlxmlgoogle-webfonts

提问by Jér?me Verstrynge

I am trying to include webfonts in the template of a Blogger blog:

我正在尝试在 Blogger 博客的模板中包含 webfonts:

<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE html>
<html b:version='2' class='v2' expr:dir='data:blog.languageDirection' xmlns='http://www.w3.org/1999/xhtml' xmlns:b='http://www.google.com/2005/gml/b' xmlns:data='http://www.google.com/2005/gml/data' xmlns:expr='http://www.google.com/2005/gml/expr'>
  <head>
    <link href='http://fonts.googleapis.com/css?family=Share:400,700&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
    <link href='http://fonts.googleapis.com/css?family=Istok+Web:400,700&subset=latin,latin-ext' rel='stylesheet' type='text/css'>
    <meta content='IE=EmulateIE7' http-equiv='X-UA-Compatible'/>
    <b:if cond='data:blog.isMobile'>
      <meta content='width=device-width,initial-scale=1.0,minimum-scale=1.0,maximum-scale=1.0' name='viewport'/>
    <b:else/>

And when I try to save the template, I get:

当我尝试保存模板时,我得到:

Error parsing XML, line 5, column 76: The reference to entity "subset" must end with the ';' delimiter.

I tried to add a ;but unsuccessfully. The links are generated and taken from Google Web Font.

我试图添加一个;但没有成功。这些链接是从 Google Web Font 生成和获取的。

How should I solve this issue? Thanks.

我应该如何解决这个问题?谢谢。

回答by zneak

That's because &is a reserved character in XML that means "an XML entity begins here". XML entities let you print characters or sequences of characters that are hard for you to embed in your document literally, either because you don't have it on your keyboard or because the document encoding forbids it. For instance, in (X)HTML, &eacute;prints the character "é", which is not easy to find on most US keyboard. (Available entities depend on the <!DOCTYPE>declaration of your XML document.)

这是因为&是 XML 中的保留字符,表示“XML 实体从这里开始”。XML 实体让您可以打印难以逐字嵌入到文档中的字符或字符序列,因为您的键盘上没有它,或者因为文档编码禁止它。例如,在 (X)HTML 中,&eacute;打印字符“é”,这在大多数美式键盘上都不容易找到。(可用实体取决于<!DOCTYPE>您的 XML 文档的声明。)

The problem with that scheme is that it means you can't unambiguously leave literal &characters around your document if they can be the start of an entity, so you need to encode them as an entity to solve that problem.

该方案的问题在于,&如果它们可以作为实体的开头,则您不能在文档周围明确地留下文字字符,因此您需要将它们编码为实体来解决该问题。

You will need to replace all your stray &with &amp;, which will print &without angering the XML parser. In your case, you should be good with replacing &subset=by &amp;subset=in your two <link>tags.

您将需要更换所有的流浪&&amp;,这将打印&不激怒XML解析器。在你的情况,你要善于用替换&subset=通过&amp;subset=在你的两个<link>标签。

回答by Jim

Ampersands in XML indicate the start of an entity reference. It starts with an ampersand, then there's a marker indicating which entity it is referring to, then a semicolon to end it. In order to include a literal ampersand in a document, you need to use a character entity reference that refers to an ampersand, i.e. &amp;.

XML 中的 & 符号表示实体引用的开始。它以 & 号开头,然后有一个标记指示它所指的实体,然后是一个分号来结束它。为了在文档中包含文字&符号,您需要使用引用&符号的字符实体引用,即&amp;.

As you have not done this, the parser is trying to parse the following data as if it were an entity reference, which it is not. That is why it fails to parse - it can't find the semi-colon at the end of the entity reference because it's not supposed to be an entity reference.

由于您还没有这样做,解析器正在尝试解析以下数据,就好像它是实体引用一样,但事实并非如此。这就是它无法解析的原因——它在实体引用的末尾找不到分号,因为它不应该是实体引用。

For instance, where you have:

例如,您有:

http://fonts.googleapis.com/css?family=Share:400,700&subset=latin,latin-ext

You should have:

你应该有:

http://fonts.googleapis.com/css?family=Share:400,700&amp;subset=latin,latin-ext