jam*_*iss 13 html html5 vocabulary microdata schema.org
假设我有一个关于一个人找到工作的简单HTML页面:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>New Job for John Doe</title>
</head>
<body>
<h1>New Job for John Doe</h1>
<p>This week John Doe accepted an offer to become a Software Engineer at MITRE. John graduated from MIT in 2005 with a BS in Computer Science. He previously worked at a small company near Boston. Blah, blah, blah.</p>
<p>The MITRE Corporation is a not-for-profit organization chartered to work in the public interest. The MITRE Corporation has two principal locations: Bedford, Massachusetts, and McLean, Virginia. Blah, blah, blah.</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
如果我使用schema.org词汇表添加语义数据,它可能如下所示:
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>New Job for John Doe</title>
</head>
<body>
<h1>New Job for John Doe</h1>
<p itemscope itemtype="http://schema.org/Person">This week John Doe accepted an offer to become a <span itemprop="jobTitle">Software Engineer</span> at <span itemprop="worksFor">MITRE</span>. John graduated from <span itemprop="alumniOf">MIT</span> in 2005 with a BS in Computer Science. He previously worked at a small company near Boston. Blah, blah, blah.</p>
<p itemscope itemtype="http://schema.org/Corporation">The MITRE Corporation is a not-for-profit organization chartered to work in the public interest. The MITRE Corporation has two principal locations: <span itemprop="location">Bedford, Massachusetts</span>, and <span itemprop="location">McLean, Virginia</span>. Blah, blah, blah.</p>
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
第一段显然是关于人,John Doe,第二段是关于公司,MITRE公司.但第一段中的"MITRE"与第二段中的"MITRE公司"相同.如何使用schema.org明确声明这些是同一个?
我第一次尝试回答我自己的问题是使用 itemref 属性,如下所示:
<p itemscope itemtype="http://schema.org/Person">
This week John Doe accepted an offer to become a
<span itemprop="jobTitle">Software Engineer</span>
at <span itemprop="worksFor" itemref="TheMitreCorporation">MITRE</span>.
John graduated from <span itemprop="alumniOf">MIT</span>
in 2005 with a BS in Computer Science.
He previously worked at a small company near Boston. Blah, blah, blah.
</p>
<p itemscope itemtype="http://schema.org/Corporation" id="TheMitreCorporation">
The MITRE Corporation is a not-for-profit organization chartered to work in the public interest.
The MITRE Corporation has two principal locations:
<span itemprop="location" itemscope itemtype="http://schema.org/Place">
<span itemprop="name">Bedford, Massachusetts</span>
</span>, and
<span itemprop="location" itemscope itemtype="http://schema.org/Place">
<span itemprop="name">McLean, Virginia</span>
</span>. Blah, blah, blah.
</p>
Run Code Online (Sandbox Code Playgroud)
但一些评论者正确地指出这不是该属性的正确使用方式。
这是我的第二次尝试:改用该itemid属性。公司名称的两个实例都被赋予一个itemscopeanditemtype属性,并且它们都设置为相同的itemid值,即 URL。
规范说:“如果指定了 itemid 属性,则其值必须是可能被空格包围的有效 URL...项目的全局标识符是其元素的 itemid 属性的值,如果有一个,则解析为相对值指定该属性的元素...不得在未同时指定 itemscope 属性和 itemtype 属性的元素上指定 itemid 属性。”
<p itemscope itemtype="http://schema.org/Person">This week John Doe accepted an offer to become a <span itemprop="jobTitle">Software Engineer</span> at <span itemprop="worksFor" itemscope itemtype="http://schema.org/Corporation" itemid="http://www.mitre.org">MITRE</span>. John graduated from <span itemprop="alumniOf">MIT</span> in 2005 with a BS in Computer Science. He previously worked at a small company near Boston. Blah, blah, blah.</p>
<p itemscope itemtype="http://schema.org/Corporation" itemid="http://www.mitre.org">The MITRE Corporation is a not-for-profit organization chartered to work in the public interest. The MITRE Corporation has two principal locations: <span itemprop="location" itemscope itemtype="http://schema.org/Place"><span itemprop="name">Bedford, Massachusetts</span></span>, and <span itemprop="location" itemscope itemtype="http://schema.org/Place"><span itemprop="name">McLean, Virginia</span></span>. Blah, blah, blah.</p>
Run Code Online (Sandbox Code Playgroud)