一般
schema.org 上的文档中有一个getting started page。当您正在构建字典时,您可能在那里有一个关于电影的条目(他们正在使用的示例)。标记可能如下所示:
<div itemscope itemtype ="http://schema.org/Movie">
<h1 itemprop="name">Avatar</h1>
<span>Director: <span itemprop="director">James Cameron</span></span>
<span itemprop="genre">Science fiction</span>
<a href="../movies/avatar-theatrical-trailer.html" itemprop="trailer">Trailer</a>
</div>
这要求您知道您的数据输入当然是一部电影。如果您不知道,您可以使用 itemtype Article(甚至是 Thing)和全局属性 name 和 description。
还有关于 格式 的附加信息,例如日期以及如何使用meta tag 和设置content 属性来整合不可见数据:<meta itemprop="bestRating" content="5" />。
您始终可以通过指定属性additionalType 为项目赋予多种类型。你甚至可以extend the schema。但是您应该谨慎使用它们,因为它们不会被搜索引擎识别,但将来可能会被使用:
如果架构获得采用并证明对搜索应用程序有用,搜索引擎可能会开始使用这些数据。
一般来说,所有这些标记都是可选的,因此请尽可能多地标记,但只标记那些有意义的部分。来自schema.org FAQ:
只标记项目的某些属性很好 - 标记不是全有或全无的选择。
标记验证
为了测试您的标记,Google 提供了Rich Snippets Testing Tool。您可以在那里粘贴您的 HTML,然后查看 Google 从中提取的内容。对于上面的例子,结果如下:
Item
Type: http://schema.org/movie
name = Avatar
director = James Cameron
genre = Science fiction
trailer
text = Trailer
href = http://www.example.com/movies/avatar-theatrical-trailer.html
在您的页面上
由于您页面上的信息是用户生成的,您可以让用户从更高级别的 schema.org 类型中进行选择(Movie、Place(麻省理工学院宿舍)、SportsEvent(2012 年伦敦奥运会)等.) 并回退到Thing。然后获取与这些类型的属性匹配的表单元素中的数据。保存数据并在构建字典页面时对其进行评估。然后由 Google(和其他人)抓取并用于索引。
对于您提供的 Gmail 示例,标记可能如下所示(将其复制并粘贴到 testing tool 以查看 Google 是否理解嵌套):
<div itemscope itemtype ="http://www.schema.org/SoftwareApplication">
<h1 itemprop="name">Gmail</h1>
<div itemprop="comment" itemscope itemtype="http://www.schema.org/Comment">
<span itemprop="comment">Google's email service</span>
<span itemprop="author">user63</span>
</div>
<div itemprop="comment" itemscope itemtype="http://www.schema.org/Comment">
<span itemprop="comment">best email service in terms of spam prevention</span>
<span itemprop="author">user21</span>
</div>
<div itemprop="comment" itemscope itemtype="http://www.schema.org/Comment">
<span itemprop="comment">Gmail has a support of IMAP, POP3, SMTPi OAUTH, FRD, two-way secure login</span>
<span itemprop="author">userMew</span>
</div>
</div>
附加信息
有关详细信息,请参阅Google schema.org FAQs。另请参阅Dublin Core Metadata Initiatice (DCMI) (Wikipedia) 作为对数据进行语义标记的替代方法。他们还有a wiki page for mapping between schema.org and DC。