HTML5 和 RDFa 支持

发布于 2024-10-02 04:54:44 字数 698 浏览 5 评论 0原文

我即将向现有的 HTML5 Web 应用程序引入开放图谱协议,并且我希望包含必要的 RDFa 数据,而不引入任何不必要的杂项。

我查看了 HTML+RDFa 1.1 草案并将其与 Facebook的Open Graph协议文档,我只需要在html元素上设置lang属性而且它已经为 HTML5 做好了准备:

<html lang="en">
<head xmlns:og="http://opengraphprotocol.org/schema/">
    <title>The Rock (1996)</title>
    <meta property="og:title" content="The Rock"/>
    <meta property="og:type" content="movie"/>
    ...

最初,我对 HTML5 中的 RDFa 支持感到困惑,因为有很多消息来源声称它无法以有效的方式完成,直到我最终进入草案。我不是手头问题的专家,所以如果有人能看一下这个并评论该草案在当今浏览器中所享有的支持,我将不胜感激。

I'm about to introduce the Open Graph protocol to an existing HTML5 Web application and I'd like to include the necessary RDFa data without introducing any unnecessary crud.

I've looked at the HTML+RDFa 1.1 draft and comparing it with Facebook's Open Graph protocol documentation, I just need to set the lang attribute on the html element and it's HTML5 ready:

<html lang="en">
<head xmlns:og="http://opengraphprotocol.org/schema/">
    <title>The Rock (1996)</title>
    <meta property="og:title" content="The Rock"/>
    <meta property="og:type" content="movie"/>
    ...

Initially, I grew confused about RDFa support in HTML5 with so many sources claiming it cannot be done in a valid manner, until I finally landed on the draft. I'm no expert on the matters at hand, so I'd appreciate if someone could take a look at this and also comment about the support the draft enjoys in today's browsers.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

£冰雨忧蓝° 2024-10-09 04:54:44

W3C 验证器抱怨每一个

<meta property="whatever" content...

要求属性应该被

<meta name="whatever ...

替换的要求,对吧?如果 facebook 是您最关心的,我很高兴告诉您,它可以容忍后一种形式,所以就用它吧:

<meta name="og:title" content="My nice picture"/>
<meta name="og:type" content="article"/>
<meta name="og:url" content="http://foobar123.com/test/simple.php"/>

当使用 FB 进行测试时:当心,FB 会缓存页面解析(全局, facebook 端,硬重新加载不会有帮助)因此,每次更改某些内容以测试 facebook 发布时,请确保向 url 添加“唯一”(但毫无意义)路径信息或 GET 参数:

mysite.com/test.php/bogusParam1
mysite.com/test.php/bogusParam2
mysite.com/test.php/bogusParam3
...
mysite.com/test.php?foo=hello
mysite.com/test.php?foo=howdy
mysite.com/test.php?foo=aloha

The W3C validator moans about every

<meta property="whatever" content...

demanding that the property shall be

<meta name="whatever ...

instead, right? If facebook is, what you mostly care about, I am happy to tell, it tolerates the latter form, so just go for it:

<meta name="og:title" content="My nice picture"/>
<meta name="og:type" content="article"/>
<meta name="og:url" content="http://foobar123.com/test/simple.php"/>

When testing with FB: Beware, that FB caches page parsings (globally, facebook-side, hard reload won't help) so make sure to add a 'unique' (but pointless) path-info or GET Parameter to the url everytime you change something to test facebook-posting of it:

mysite.com/test.php/bogusParam1
mysite.com/test.php/bogusParam2
mysite.com/test.php/bogusParam3
...
mysite.com/test.php?foo=hello
mysite.com/test.php?foo=howdy
mysite.com/test.php?foo=aloha
杯别 2024-10-09 04:54:44

HTML5 和 HTML+RDFa 1.1 都仍在开发中,这意味着我们现在所说的一切可能会发生变化。你的问题有两个方面:

  • 它有效吗?
  • 它会产生互操作性问题吗?

对于有效性,您可以定期检查W3C 验证器中规范的实施状态。它内置了一个实验性的 HTML5 验证器。

HTML5 中的命名空间仍然存在很大争议。它们产生的问题导致 DOM 与真正的预期不同,这引出了我的第二个问题:互操作性问题。您可以测试如何使用 Live Dom Viewer 或使用 Opera Dragonfly 之类的东西来探索浏览器中文档的 DOM 表示。

如果您想进一步探索 HTML5 DOM 和 RDFa 主题,您可能需要阅读 Jenni 的 博客发布

到目前为止,您的标记并不是真正的问题,但如果您涉及 JavaScript,则必须小心命名空间和列值。

Both HTML5 and HTML+RDFa 1.1 are still in development, it implies that everything we say her now might be subject to change. There are two sides of your questions:

  • Is it valid?
  • Will it create interoperability issues?

For the validity, you might check at regular pace the implementation status of specifications in the W3C validator. It has an experimental HTML5 validator built into it.

Namespaces in HTML5 are still pretty much in debate. They create issues leading to a different DOM from what is really intended, which leads to my second question: interoperability issues. You can test how the markup is handled with a Live Dom Viewer or use something like Opera Dragonfly to explore the DOM representation of the document in the browser.

If you want to explore the topic of HTML5 DOM and RDFa a bit more, you might want to read Jenni's blog post.

Your markup so far is not really an issue, but if you involve javascript, you will have to be careful about namespaces and values with columns.

笛声青案梦长安 2024-10-09 04:54:44

2009 年的草案似乎试图构建一个对两者都有效的模式。

http://dev.w3.org/html5/rdfa/rdfa-module.html

This 2009 Draft seems to be trying to build a schema which validates for both.

http://dev.w3.org/html5/rdfa/rdfa-module.html

西瑶 2024-10-09 04:54:44

这是在 html5 中执行此操作的正确方法:

    <meta property="http://ogp.me/ns#locale" content="en_US" />
<meta property="http://ogp.me/ns#site_name" content="xxxxxx" />
<meta property="http://ogp.me/ns#type" content="website" />
<meta property="http://ogp.me/ns#title" content="xxxxxxxxxxxx" />
<meta property="http://ogp.me/ns#description" content="xxxxxxxxxxxxxxxx" />
<meta property="http://ogp.me/ns/fb#app_id" content="xxxxxxxxxxxxxxxx" />   

等等...
希望有帮助

This is the corect way to doit in html5:

    <meta property="http://ogp.me/ns#locale" content="en_US" />
<meta property="http://ogp.me/ns#site_name" content="xxxxxx" />
<meta property="http://ogp.me/ns#type" content="website" />
<meta property="http://ogp.me/ns#title" content="xxxxxxxxxxxx" />
<meta property="http://ogp.me/ns#description" content="xxxxxxxxxxxxxxxx" />
<meta property="http://ogp.me/ns/fb#app_id" content="xxxxxxxxxxxxxxxx" />   

etc...
hope it helps

甜警司 2024-10-09 04:54:44

现在,HTML5 验证器和 Facebook 都支持 HTML+RDFa 1.1,因此您现在可以只使用属性而不是名称。您也不必搞乱 html5 中的 xmlns 声明。 og 前缀在 (RDFa) 规范中定义,因此您不必定义它。不过,您可以在 html 或 head 标记上明确地说 prefix="og: http://ogp.me/ns#"

Now a days, The HTML5 validator and Facebook both support HTML+RDFa 1.1, so you can just use property instead of name now. You also don't have to mess with xmlns declarations in html5. The og prefix is defined in the (RDFa) spec, so you don't have to define it. You could explicitly say prefix="og: http://ogp.me/ns#" on the html or head tag though.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文