Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Microdata ItemID to identify elements scattered throughout an HTML doc/HTML tables

My developer coded a list of Products using HTML Tables. The code came out something like this:

<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>

You get the idea. Visually it looks perfect, but when attempting to markup via schema.org, I'm running into issues, being that the products properties don't exist is neat nested HTML elements, but are spread across the table. Would there be a way to use the ItemID Microdata attribute to make sure each brand and price is associated with the right product name?

Something like:

<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>

Etc., etc. Any thoughts? Will I have the re-code the pages to make this work?

like image 206
Michael Hayes Avatar asked Jun 19 '12 21:06

Michael Hayes


People also ask

What is the use of microdata in HTML?

Microdata is an attempt to provide a simpler way of annotating HTML elements with machine-readable tags than the similar approaches of using RDFa and classic microformats. At a high level, microdata consists of a group of name-value pairs. The groups are called items, and each name-value pair is a property.

What is the function of microdata in html5?

Microdata lets you define your own custom-tailored elements and start implanting custom-tailored properties in your web pages. At a high level, microdata comprises a set of name-value pairs. Microdata syntax consists of a set of (name-value) that can be acquired using machine parsing tools.

What is HTML Itemid?

The itemid global attribute provides microdata in the form of a unique, global identifier of an item. An itemid attribute can only be specified for an element that has both itemscope and itemtype attributes.

What is microdata schema?

Schema.org (often called schema) is a semantic vocabulary of tags (or microdata) that you can add to your HTML to improve the way search engines read and represent your page in SERPs.


2 Answers

Actually, itemid would not be the correct way to do this. Unlike RDF, the microdata parsing model doesn't join things that have the same itemid.

Instead, you should use the itemref attribute.

For example:

<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>

You can test microdata using https://webmaster.yandex.com/tools/microtest/ in addition to Google.

like image 95
linclark Avatar answered Nov 01 '22 21:11

linclark


Yes, itemid is the right way to do this. Your example would look something like this:

<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>

By re-using the same itemid you're telling the microdata parser that you're talking about the same item in different parts of the page.

like image 29
Shawn Simister Avatar answered Nov 01 '22 19:11

Shawn Simister