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

穿精又带淫゛_ 提交于 2019-11-26 07:49:44

问题


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?


回答1:


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>


来源:https://stackoverflow.com/questions/27869288/is-there-a-microdata-tag-to-designate-whether-a-value-is-a-number-string-or-bo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!