This specification defines a DOM API for accessing RDFa data contained in a structured document, such as SVG, XHTML or HTML. The RDFa DOM API can be used to extract a specific RDF triple, or set of triples, based on a subject query.

Introduction

RDFa [[!RDFA-SYNTAX]] has seen substantial growth since it became an official W3C Recommendation in October 2008. It has seen wide adoption among search companies, e-commerce sites, governments, and content management systems. There are numerous interoperable implementations and growth is expected to continue to rise.

In an effort to ensure that browser-based applications are able to fully utilize RDFa, this specification outlines a set of routines that are capable of extracting RDFa from web pages for use in Javascript applications, as well as browser extensions. The RDFa DOM API allows a programmer to query the RDF model expressed by a document and then make programmatic decisions based on the semantic data embedded in the page.

The RDFa DOM API

The RDFa DOM API strives to be a simple set of calls that a developer may use to retrieve triples contained in the document.

Triples

readonly attribute DOMString subject
The subject URL associated with the RDF triple.
readonly attribute DOMString predicate
The predicate URL associated with the RDF triple.
readonly attribute DOMString object
The object URL or literal data associated with the RDF triple.
readonly attribute DOMString datatype
The datatype URL associated with the object literal. Null if there is no associated datatype.
readonly attribute DOMString language
The language associated with the object literal. Null if there is no associated language.
readonly attribute Triple[] children
A list of triples that contain the same subject as this triple.

The Document Interface

This section describes the set of additional methods that must be defined on the standard Document interface as defined in [[!DOM-LEVEL-2-CORE]].

Triple[] getTriplesByType ()
Retrieves a list of triples given a subject type.
optional DOMString? type
Specifies the subject type.

The type parameter may be null or an empty string. In both cases, all subjects from the page should be returned in the array of Triple objects.

The getTriplesByType method allows both full URI specification as well as short-hand specification. A type may be given by specifying a complete URI, for example http://xmlns.com/foaf/0.1/Person, or a short-hand DOMString such as Person.

To perform a match, a direct string comparison is performed. If the string comparison fails, the given type is checked against a subject's type starting at the last character in each string and moving backwards. Each character is compared until there is a character mis-match, or all of the characters in the type string are exhausted. If all of the characters in the type string are exhausted and there were no character mis-matches, the subject's type must be considered a match.

Storing and Retrieving RDF Triples

This section will contain best practices on storing and retrieving triples on a page.

Acknowledgements

This document has been prepared with the help of the following people (in alphabetical order):