Is there a microdata tag to designate whether a value is a number, string, or bool?

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:

  • free property:

    Values expected to be one of these types:
    Boolean

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>

Leave a Comment