微数据ItemID,用于标识分散在HTML doc / HTML表中的元素

时间:2012-06-19 21:23:41

标签: microdata schema.org

我的开发人员使用HTML表格编制了产品列表。代码出现如下:

<table>
<tr  class="name">
<td>Product Name #1</td><td>Product Name #2</td><td>Product Name #3</td>
</tr>
<tr class="price">
<td>Product Price #1</td><td>Product Price #2</td><td>Product Price #3</td>
</tr>
<tr class="brand">
<td>Product Brand #1</td><td>Product Brand #2</td><td>Product Brand #3</td>
</tr>
</table>

你明白了。在视觉上它看起来很完美,但是当尝试通过schema.org进行标记时,我遇到了问题,因为产品属性不存在是整齐的嵌套HTML元素,而是分布在整个表中。是否有办法使用ItemID Microdata属性来确保每个品牌和价格与正确的产品名称相关联?

类似的东西:

<tr class="name">
<td itemscope itemtype="http://www.schema.org/Product" itemID="Product1">Product Name #1</td>
<td itemscope itemtype="http://www.scema.org/Product" itemID="Product2">Product Name #2</td>

等等,有什么想法吗?我是否会对页面进行重新编码以使其正常工作?

2 个答案:

答案 0 :(得分:7)

是的,itemid是执行此操作的正确方法。你的例子看起来像这样:

<table>
  <tr class="name">
    <td itemscope itemtype="http://www.schema.org/Product" itemid="Product1">
      <span itemprop="name">Product Name #1</span>
    </td>
    <td itemscope itemtype="http://www.schema.org/Product" itemid="Product2">
      <span itemprop="name">Product Name #2</span>
    </td>
  </tr>
  <tr class="price">
    <td itemscope itemtype="http://www.schema.org/Product" itemid="Product1">
      <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
        <span itemprop="price">Product Price #1</span>
      </div>
    </td>
    <td itemscope itemtype="http://www.schema.org/Product" itemid="Product2">
      <div itemprop="offers" itemscope itemtype="http://schema.org/Offer">
        <span itemprop="price">Product Price #2</span>
      </div>
    </td>
  </tr>
</table>

通过重复使用相同的itemid,您告诉微数据解析器您正在讨论页面不同部分中的相同项目。

答案 1 :(得分:7)

实际上,itemid不是正确的方法。与RDF不同,微数据解析模型不会加入具有相同itemid的内容。

相反,您应该使用itemref属性。

例如:

<div itemscope itemtype="http://schema.org/Product" itemref="foo"></div>
<div id="foo" itemprop="offers" itemscope itemtype="http://schema.org/Offer">
  <span itemprop="price">Product Price #1</span>
</div>

除Google之外,您还可以使用https://webmaster.yandex.com/tools/microtest/测试微数据。