HTML 前缀属性(开放图谱协议)的含义?

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

Meaning of HTML prefix attribute (Open Graph Protocol)?

htmlfacebookvalidationfacebook-opengraph

提问by John Sonderson

I'm new to Facebook Open Graph Protocol. I have been trying to figure out what the meaning of the HTML prefixattribute is. The closest post on Stack Overflow I could find dealing with this subject is this postwhich was very helpful as it deals with what the differences are among the various possible syntaxes and which one to use.

我是Facebook 开放图谱协议的新手。我一直在试图弄清楚 HTMLprefix属性的含义是什么。我能找到的关于 Stack Overflow 的最接近这个主题的帖子这篇文章,它非常有帮助,因为它处理了各种可能的语法之间的差异以及要使用的语法。

However the post does not say anything about what this prefixattribute is or what it does. AFAIK this is not a standard HTML attribute. I was able to find this documentwhich I think is where the W3C defines this attribute but was not able to make any sense of it.

然而,这篇文章没有说明这个prefix属性是什么或它做什么。AFAIK 这不是标准的 HTML 属性。我能够找到这个文档,我认为它是 W3C 定义此属性的地方,但无法理解它。

Could someone please explain to me:

有人可以向我解释一下:

  1. What does the prefixattribute do?

  2. Can I write

    <html prefix="og:http://ogp.me/ns#">

    instead of

    <html prefix="og: http://ogp.me/ns#">

    or would that be a syntax error?

  3. Can I include multiple prefixattributes for any given HTML tag?

    <head prefix="a: http://www.aaa.com/ns#" prefix="b: http://www.bbb.com/ns#">

    Based on my knowledge of HTML, this would be wrong, but then prefixis a nonstandard attribute. So perhaps, what I would like to know is, can I write:

    <head prefix="a: http://www.aaa.com/ns# b: http://www.bbb.com/ns#">

    or does specifying multiple prefixes at any place in the HTML tree not make sense for some reason?

  4. If this prefixtag is not part of the HTML spec, how would submitting a page containing this attribute to a code validator ever result in my code being standards compliant?

  1. 什么是prefix属性呢?

  2. 我可以写吗

    <html prefix="og:http://ogp.me/ns#">

    代替

    <html prefix="og: http://ogp.me/ns#">

    或者这会是一个语法错误吗?

  3. 我可以prefix为任何给定的 HTML 标签包含多个属性吗?

    <head prefix="a: http://www.aaa.com/ns#" prefix="b: http://www.bbb.com/ns#">

    根据我对 HTML 的了解,这是错误的,但这prefix是一个非标准属性。所以也许,我想知道的是,我可以写:

    <head prefix="a: http://www.aaa.com/ns# b: http://www.bbb.com/ns#">

    或者在 HTML 树中的任何位置指定多个前缀是否出于某种原因没有意义?

  4. 如果此prefix标记不是 HTML 规范的一部分,那么将包含此属性的页面提交给代码验证器将如何导致我的代码符合标准?

Thank you for answering my questions.

谢谢你回答我的问题。

回答by tayllan

First:

第一的:

prefixis oneof the attributes defined by the RDFa (Resource Description Framework in Attributes)extension. RDFais used to implement the Semantic Webin web pages represented in many markup languages, like HTML and XML. Instead of having a web page telling the browser just how it should be structured, now you can also tell it what the page represents, like a Person, a List of Products, etc.

prefixRDFa(属性中的资源描述框架)扩展定义的属性之一RDFa用于在以多种标记语言(如 HTML 和 XML)表示的网页中实现语义 Web。不是让一个网页告诉浏览器它应该如何结构,现在你还可以告诉它页面代表什么,比如一个人、一个产品列表等。

And for you to be able to semantically represent data on your web page, you need to use a semantic vocabulary, which tells the browser exactly that: what's being represented in your page. A popular semantic vocabularyis schema.org.

并且为了能够在您的网页上语义地表示数据,您需要使用语义词汇表,它可以准确地告诉浏览器:您的页面中所表示的内容。一个流行的语义词汇schema.org

But sometimes a singular semantic vocabulary cannot represent and describe all of your web page. That's where the prefixattribute comes in:

但有时一个单一的语义词汇无法代表和描述您的所有网页。这就是prefix属性的用武之地:

What does the prefixattribute do?

什么是prefix属性呢?

The prefixattribute allows you to specify one or more semantic vocabulariesbeing used. The following example uses two vocabularies to represent a Personthat has a favorite Animal: schema.organd vocab.org.

prefix属性允许您指定一个或多个正在使用的语义词汇。以下示例使用两个词汇表来表示拥有最喜欢的 Animal的 Personschema.orgvocab.org

<p vocab="http://schema.org/" prefix="ov: http://open.vocab.org/terms/" resource="#manu" typeof="Person">
    My name is <span property="name">MY_NAME</span>

    and my telephone is <span property="telephone">MY_TELEPHONE</span>.

    My favorite animal is the <span property="ov:preferredAnimal">FAVORITE_ANIMAL</span>.
</p>

Can I write <html prefix="og:http://ogp.me/ns#">instead of <html prefix="og: http://ogp.me/ns#">or would that be a syntax error?

我可以<html prefix="og:http://ogp.me/ns#">代替写<html prefix="og: http://ogp.me/ns#">还是会出现语法错误?

Besides from not being able to find any examples on the web using the former syntax, from the specification of the RDFa Coreyou can see that at least one space is indeed mandatory:

除了无法在网络上找到任何使用前一种语法的示例之外,从RDFa Core的规范中您可以看到至少一个空格确实是强制性的:

prefix
    a white space separated list of prefix-name IRI pairs of the form
    NCName ':' ' '+ xsd:anyURI

Can I include multiple prefixattributes for any given HTML tag?

我可以prefix为任何给定的 HTML 标签包含多个属性吗?

Yes, you can. From the specification of the prefixattribute given above, and from lots of examples given on the specification of the RDFa Core, the following is allowed:

是的你可以。根据prefix上面给出的属性规范,以及RDFa Core规范中给出的大量示例,允许以下内容:

<html
    prefix="foaf: http://xmlns.com/foaf/0.1/
            dc: http://purl.org/dc/terms/"
>
    <!-- your page -->
</html>

If this prefixtag is not part of the HTML spec, how would submitting a page containing this attribute to a code validator ever result in my code being standards compliant?

如果此prefix标记不是 HTML 规范的一部分,那么将包含此属性的页面提交给代码验证器将如何导致我的代码符合标准?

As mentioned by @wensveen, HTML5 supports the RDFa attributes out-of-the-box.

正如@wensveen 所提到的,HTML5 支持 RDFa 属性 out-of-the-box

回答by wensveen

It appears the prefix attribute is indeed defined in the RDFa specification you linked. While you need to specify the correct media type for XHTML documents (application/xhtml+xml) and the correct doctype (<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">) and probably some more XML push-ups, this isn't necessary for HTML5. In HTML5 you can use the RDFa-defined attributes out-of-the-box.

看来前缀属性确实是在您链接的 RDFa 规范中定义的。虽然您需要为 XHTML 文档指定正确的媒体类型 ( application/xhtml+xml) 和正确的 doctype ( <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML+RDFa 1.1//EN" "http://www.w3.org/MarkUp/DTD/xhtml-rdfa-2.dtd">) 并且可能还有一些 XML 俯卧撑,但这对于 HTML5 来说不是必需的。在 HTML5 中,您可以开箱即用地使用 RDFa 定义的属性。

See: HTML+RDFa 1.1 specification

参见:HTML+RDFa 1.1 规范

I don't know if there are any specific advantages of this way of mapping a prefix to a namespace. It isn't entirely clear to me either.

我不知道这种将前缀映射到命名空间的方式是否有任何特定优势。我也不是很清楚。