[whatwg] Microdata DOM API
philipj at opera.com
Thu Aug 20 15:50:51 PDT 2009
There are already two demos of converting Microdata to other formats which
I found quite useful . I've taken a closer look at the Microdata DOM
A few issues came up in the process:
To avoid total confusion I'll use item-property and DOM-property to
The spec says that "properties can also themselves be groups of name-value
pairs", but this isn't exposed in a very convenient way in the DOM API.
The 'properties' DOM-property is a HTMLPropertyCollection of all
associated elements. Discovering if the item-property value is a plain
string or an item seems to require item.hasAttribute('item'), which seems
out of place when everything else has been so neatly reflected. (Just
checking item.item won't work if the item attribute is empty.) Also, the
'contents' DOM-property is always the item-property value except in the
case where the item-property is another item -- in that case it is
something random like .href or .textContent depending on the element type.
I think it would be better if the DOM-property were simply called 'value'
(the spec does talk about name-value pairs after all) and corresponded
more exactly to 'property value' . Elements that have no 'property
names'  should return null and otherwise elements with an 'item'
attribute should return itself, although I don't think it should be
writable in that case. One might also/otherwise consider adding a
valueType DOM-property which could be 'string', 'item' or something
One example  uses document.items[item].names but document.items isn't
defined anywhere. I assume this is an oversight and that it is equivalent
to document.getItems() Further, names is a member of
HTMLPropertyCollection, so document.items[item].properties.names is
probably intended instead of document.items[item].names. Assuming this the
example actually produces the output it claims to.
Shouldn't namedItem  be namedItems? Code like .namedItem().item(0)
would be quite confusing. Also, RadioNodeList should be PropertyNodeList.
I think many will wonder why item and itemprop can't be given on a single
element for compactness:
<span item="org.example.fruit" itemprop="org.example.name">Apple</span>s
and <span item="org.example.fruit"
itemprop="org.example.name">Orange</span>s don't compare well.
Allowing this would complicate the definition of 'corresponding item' ,
but I think that might be acceptable. I suggest either allowing it or
adding a note explaining why it isn't allowed and giving examples of
Doing Microdata just for fun, not for Opera Software.
More information about the whatwg