2

There is an HTML5 attribute called datetime that indicates that a value type is a datetime. But I see no way to indicate whether a itemprop value in span tag is a string, bool, or number. Am I right that there is no way to include this kind of information in microdata? If so, is there some reason why this capability should be omitted?

dan
  • 43,914
  • 47
  • 153
  • 254

1 Answers1

3

The Microdata specification only differs between these types of values, which get derived from the HTML5 markup:

  • item (if an element has an itemprop and an itemscope attribute)
  • absolute URL (if the itemprop is specified on an URL property element like a, video etc.)
  • datetime (if the itemprop is specified on a time element)
  • string, i.e.,
    • for meta elements: the value of the content attribute
    • for data elements: the value of the value attribute
    • for meter elements: the value of the value attribute
    • for every other element: its textContent

While RDFa allows to specify the datatype with its datatype attribute

<span property="alive" datatype="xsd:boolean">true</span>
<!-- the value is boolean -->

… Microdata doesn’t offer such an attribute:

<span itemprop="alive">true</span>
<!-- no way to denote that the value is boolean -->

There was the idea to specify the datatype of Microdata properties in the vocabulary registry, but it seems that there was no consensus for this.

What do to?

Vocabularies could define in their descriptions which values their properties should/must have.

The vocabulary Schema.org expects (and does intentionally not require) specific types. Examples:

The vocabulary vCard (as defined by the WHATWG) requires values types. Examples:

  • anniversary property:

    The value must be a valid date string.

  • sex property:

    The value must be one of F, meaning "female", M, meaning "male", N, meaning "none or not applicable", O, meaning "other", or U, meaning "unknown".

Of course one could use/create a Microdata vocabulary to make such statements about other Microdata vocabularies, similar to RDFS. Schema.org is using RDFa to define their types/properties, and they also use RDFS, but instead of defining a range with rdfs:range (which would mean that all property values are (also) of that type), they made their own property rangeIncludes, which doesn’t allow this inference:

<div typeof="rdf:Property" resource="http://schema.org/free">
  <span class="h" property="rdfs:label">free</span>
  <span property="rdfs:comment">A flag to signal that the publication is accessible for free.</span>
  <span>Domain: <a property="http://schema.org/domainIncludes" href="http://schema.org/PublicationEvent">PublicationEvent</a></span>
  <span>Range: <a property="http://schema.org/rangeIncludes" href="http://schema.org/Boolean">Boolean</a></span>
</div>
unor
  • 92,415
  • 26
  • 211
  • 360
  • It looks like the `meter` element can be used for numeric elements. "For numeric data, the meter element and its value attribute can be used instead." http://www.w3.org/TR/microdata/ – dan Jan 10 '15 at 03:10
  • @dan: This is only about HTML5 semantics (and it’s bad advice, as [`meter`](http://www.w3.org/TR/2014/REC-html5-20141028/forms.html#the-meter-element) must not be used for *any* "numeric data"), and has no effect on the datatype of the Microdata value. It’s still a string as far as Microdata is concerned. When converting Microdata to RDF, tools [could, in some cases](http://www.w3.org/TR/2014/NOTE-microdata-rdf-20141216/#value-typing), determine that the property value of `meter` (as well as `data`) is double or integer -- but this is only relevant for the RDF, not the Microdata. – unor Jan 10 '15 at 03:38