HTML5 Guidelines for Web Developers

(coco) #1
11.2 The Microdata DOM API 269

Lyle Mays
Pat Metheny Group





In this example, the two paragraphs of the blog entry are divided into two div
elements with the IDs location and intro. Within these div elements, the indi-
vidual musicians are identified as members of the band Pat Metheny Group via
itemprop attributes. The itemscope attribute is outside of the article and refers via
the itemref attribute to the IDs of those areas where the actual information can
be found. In complicated microdata structures, this option can be very useful.


11.2 The Microdata DOM API


As you would expect, the microdata structure of a document can also be explored
via JavaScript via the microdata DOM API.


Accessing all top-level microdata items (that is, those items that have an item-
scope attribute and are not part of another item) takes place via the method
document.getItems(). It returns as a result a DOM-NodeList of elements found
in the order in which they appear in the DOM tree. If we are only after items of a
particular type, we could pass a list of desired itemtype attributes, separated by
commas, in the getItems() call:


var allNodes = document.getItems();
var vCards = document.getItems(
'http://microformats.org/profile/hcard'
);


Each element of the resulting NodeList allows access to the additional micro-
data attributes present for each element. Table 11.2 lists the attribute names
and their content.


Table 11.2 Attributes of a top-level microdata item


Attribute Content

itemScope Value of itemscope attribute
itemType Value of itemtype attribute, if present

itemId Value of itemid attribute, if present
itemRef Value of itemref attribute, if present
Free download pdf