Microdata RDFa Merge
Introduction
Important: this is not a specification, or even a proposal, it's just some notes from Nathan Rixham, thinking out loud, in a publicly visible and editable space.
This page focusses on taking the best elements of Microdata and RDFa and creating a simple, for now fictional, set of attributes to handle metadata needs in HTML.
For now this note introduces the following attributes:
- item, whose presence specifies a new item, and which can also be used to set the subject/id of the item (see itemid in md, and about in RDFa).
- type, used in conjunction with item to specify the type of an item (see itemtype in md, and typeof in RDFa) -- We can't use @type - it's already defined by the SCRIPT element. We had this discussion early in the RDFa creation process and ended up at @typeof. -- manu
- property, which specifies a new property related to an item (see itemprop in md, and property in RDFa)
- vocab, which can be used to specify a schema/vocabulary, it's value can be prefixed to property and type values to use URIs as names (see vocab in RDFa)
- href and src, adopted from HTML and used to specify values which are URIs (see both md and RDFa)
- content, an attribute which allows one to specify a value associated with a property, overriding the nodes visible value (adopted from HTML meta, but available on any attribute, see <meta>, RDFa, and OpenGraph).
Example 1: Basic data
Let's start with basic data, which doesn't involve any URIs as names, it's just generic untyped data.
<section item type="Person"> Hello, my name is <span property="name">John Doe</span>, I am a <span property="title">graduate research assistant</span> at the <span property="affiliation">University of Dreams</span>. My friends call me <span property="nickname">Johnny</span>. You can visit my homepage at <a property="homepage" href="http://example.org/jd">example.org/jd</a>. <section property="address" item type="Address"> I live at <span property="street-address">1234 Peach Drive</span> <span property="locality">Warner Robins</span>, <span property="region">Georgia</span>. </section> </section>
This would produce the following Items:
{ @type: "Person", name: "John Doe", title: "graduate research assistant", affiliation: "University of Dreams", nickname: "Johnny", homepage: "http://example.org/jd", address : { @type: "Address", street-address: "1234 Peach Drive", locality: "Warner Robins", region: "Georgia" } }
Example 2: Introducing URIs as names for properties and types
The goal here is to allow URIs to be used as property and type names, in a simple lightweight manner.
To do this, we can adopt @vocab from RDFa 1.1, as such:
<section vocab="http://data-vocabulary.org/" item type="Person"> Hello, my name is <span property="name">John Doe</span> ...
This would produce the same items as example 1, however this time a @vocab is specified:
{ @vocab: "http://data-vocabulary.org/", @type: "Person", name: "John Doe", title: "graduate research assistant", affiliation: "University of Dreams", nickname: "Johnny", homepage: "http://example.org/jd", address : { @type: "Address", street-address: "1234 Peach Drive", locality: "Warner Robins", region: "Georgia" } }
Now, we can simply concatenate each property and type name with the vocab's value to create full RDF, resulting in:
@prefix dv: <http://data-vocabulary.org/> . [ rdf:type dv:Person; dv:name "John Doe"; dv:title "graduate research assistant"; dv:affiliation "University of Dreams"; dv:nickname "Johnny"; dv:homepage <http://example.org/jd>; dv:address [ rdf:type dv:Address; dv:street-address "1234 Peach Drive"; dv:locality "Warner Robins"; dv:region "Georgia" ] ]
Example 3: Introducing URIs as id's/subjects
The goal here is to allow URIs to be used as identifiers for items.
To do this, we can adopt @itemid from microdata or @about from RDFa, however I'd suggest incorporating it in to the existing @item attribute, as such:
<section vocab="http://data-vocabulary.org/" item="#jd" type="Person"> Hello, my name is <span property="name">John Doe</span> ...
This would produce the same items as example 1 and 2, but with an @id exposed (resolved relative to the document base):
{ @id: "#me", @vocab: "http://data-vocabulary.org/", @type: "Person", name: "John Doe", title: "graduate research assistant", affiliation: "University of Dreams", nickname: "Johnny", homepage: "http://example.org/jd", address : { @type: "Address", street-address: "1234 Peach Drive", locality: "Warner Robins", region: "Georgia" } }
and in RDF:
@prefix dv: <http://data-vocabulary.org/> . <#id> rdf:type dv:Person; dv:name "John Doe"; dv:title "graduate research assistant"; dv:affiliation "University of Dreams"; dv:nickname "Johnny"; dv:homepage <http://example.org/jd>; dv:address [ rdf:type dv:Address; dv:street-address "1234 Peach Drive"; dv:locality "Warner Robins"; dv:region "Georgia" ] .
Example 4: Creating non-presented metadata with @content, <meta> and <link>
This example uses a modified version of the facebook opengraph example, and introduces using <meta> with @content, and <link> with href:
<html> <head vocab="http://ogp.me/ns#"> <title>The Rock (1996)</title> <meta property="title" content="The Rock"> <meta property="type" content="movie"> <link property="url" href="http://www.imdb.com/title/tt0117500/"> <link property="image" href="http://ia.media-imdb.com/rock.jp-g"> <meta property="site_name" content="IMDb"> <meta property="http://www.facebook.com/2008/fbml/admins" content="USER_ID"> <meta property="description" content="A group of U.S. Marines, under command of a renegade general, take over Alcatraz and threaten San Francisco Bay with biological weapons."> ... </head> ... </html>
Also note how one can still use full URIs as property names as one way of using multiple vocabularies/schemas.
This note makes the @content attribute available on any node, taking precedence over a nodes visible value, as such:
<p item> Hello, my name is <span property="name" content="Mr John Doe">John</span>, </p>
The above example would use the value of "Mr John Doe" for the name, rather than "John", producing the item:
{ name: "Mr John Doe" }
Notes
- Simple mapping to a JSON / JSON-LD type format.
- Simple mapping to RDF, where needed.
- You may note that at no point do the Items exposed by the DOM change in usage
- Focus on simple token names for types and properties, limiting unexpected behaviour and allowing easy selection with CSS
- A simple rule to bootstrap @lang in to the RDF output could be used if needed.
- @datatype could optionally be included, however this would only be for RDF compatibility and would be unused in the DOM.
- @type could explicitly mark the start of a new item, even when no @item attribute is present.. unsure.
- no prefixes or namespaces because (a) they introduce non standard psuedo values and unexpected functionality where "prefix:name" is no longer a simple string token but rather a mask for another value, which is nt available in the dom or usable by CSS etc, and (b) using single vocabularies/schema's promotes reuse, handles the common case, encourages vocab/schema evolution over time and needing multple different vocabs to describe data is confusing, and often needed properties can't be found thus pushing people towards redeclaring their own new properties when identical ones already exist. Finally, you can still use properties from other vocabs by using another @vocab attribute, or by using full URIs, so no functionality is lost.