用于“&” HTML中的实体 [英] Uses for the '"' entity in HTML
问题描述
我正在修改另一方撰写的一些 XHTML 文件。作为这项工作的一部分,我正在通过 Linq到XML 进行批量编辑。
I am revising some XHTML files authored by another party. As part of this effort, I am doing some bulk editing via Linq to XML.
我刚刚注意到一些原始的来源XHTML文件包含 & quot;
HTML实体在这些文件中的文本节点。例如:
I've just noticed that some of the original source XHTML files contain the "
HTML entity in text nodes within those files. For instance:
<p>Greeting: "Hello, World!"</p>
当通过 XElement.ToString(), & quot;
实体被纯双引号替换:
<p>Greeting: "Hello, World!"</p>
问题:任何人都可以告诉我,原作者使用& quot;
实体而不是纯双引号?这些实体是否服务于我不完全欣赏的目的?或者,我怀疑他们真的没有必要吗?
Question: Can anyone tell me what the motivation might have been for the original author to use the "
entities instead of plain double-quotes? Did those entities serve a purpose which I don't fully appreciate? Or, were they truly unnecessary as I suspect?
我明白, & quot;
/ strong>在某些上下文中是必需的,例如当需要在HTML属性中放置双引号时。例如:
I do understand that "
would be necessary in certain contexts, such as when there is a need to place a double-quote within an HTML attribute. For instance:
<a href="/images/hello_world.jpg" alt="Greeting: "Hello, World!"">
Greeting</a>
推荐答案
知道动机是不可能的,不必要的在元素内容中使用& quot;
,但可能的动机包括:对HTML规则的误解;使用生成这样的代码的软件(可能是因为它的作者认为它是更安全的);并且对& quot;
的含义的误解:许多人似乎认为它产生智能报价(他们显然从未看过实际的结果)。
It is impossible, and unnecessary, to know the motivation for using "
in element content, but possible motives include: misunderstanding of HTML rules; use of software that generates such code (probably because its author thought it was "safer"); and misunderstanding of the meaning of "
: many people seem to think it produces "smart quotes" (they apparently never looked at the actual results).
无论如何,在HTML(XHTML或任何其他HTML版本)的元素内容中,从不需要使用& quot;
。任何HTML规范中都没有任何特定的含义可以给平凡的字符there分配。
Anyway, there is never any need to use "
in element content in HTML (XHTML or any other HTML version). There is nothing in any HTML specification that would assign any special meaning to the plain character " there.
正如问题所在,它在属性值,但是即使在它们中,如果值包含双引号,那么只需使用单引号作为分隔符,例如 alt ='Greeting:Hello,World!'
或者如果您被允许纠正自然语言文本中的错误,请使用正确的引号,例如 alt =问候语:Hello,World!
As the question says, it has its role in attribute values, but even in them, it is mostly simpler to just use single quotes as delimiters if the value contains a double quote, e.g. alt='Greeting: "Hello, World!"'
or, if you are allowed to correct errors in natural language texts, to use proper quotation marks, e.g. alt="Greeting: "Hello, World!""
这篇关于用于“&” HTML中的实体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!