W3C

The RDFa DOM API

W3C Editor's Draft 17 March 2010

This Version:
http://dev.w3.org/rdfa/rdfa-dom-api.html
Latest Published Version:
http://www.w3.org/TR/rdfa-dom-api/
Latest Editor's Draft:
http://dev.w3.org/rdfa/rdfa-dom-api.html
Previous version:
none
Editor:
Manu Sporny, Digital Bazaar, Inc.

Abstract

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.

Status of This Document

This section describes the status of this document at the time of its publication. Other documents may supersede this document. A list of current W3C publications and the latest revision of this technical report can be found in the W3C technical reports index at http://www.w3.org/TR/.

This document was published by the RDFa Task Force as an Editor's Draft. If you wish to make comments regarding this document, please send them to public-rdf-in-xhtml-tf@w3.org@w3.org (subscribe, archives). All feedback is welcome.

Publication as a Editor's Draft does not imply endorsement by the W3C Membership. This is a draft document and may be updated, replaced or obsoleted by other documents at any time. It is inappropriate to cite this document as other than work in progress.

This document was produced by a group operating under the 5 February 2004 W3C Patent Policy. W3C maintains a public list of any patent disclosures made in connection with the deliverables of the group; that page also includes instructions for disclosing a patent. An individual who has actual knowledge of a patent which the individual believes contains Essential Claim(s) must disclose the information in accordance with section 6 of the W3C Patent Policy.

Table of Contents

1. 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.

2. 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

interface Triple {
    readonly attribute DOMString subject;
    readonly attribute DOMString predicate;
    readonly attribute DOMString object;
    readonly attribute DOMString datatype;
    readonly attribute DOMString language;
    readonly attribute Triple[]  children;
};

2.1 Attributes

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

3. 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].

interface Document {
    Triple[] getTriplesByType (in optional DOMString? type);
};

3.1 Methods

getTriplesByType
Retrieves a list of triples given a subject type.
ParameterTypeNullableOptionalDescription
typeDOMString??Specifies the subject type.
No exceptions.
Return type: Triple[]

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.

4. Storing and Retrieving RDF Triples

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

A. Acknowledgements

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

B. References

B.1 Normative references

[DOM-LEVEL-2-CORE]
Arnaud Le Hors; et al. Document Object Model (DOM) Level 2 Core Specification. 13 November 2000. W3C Recommendation. URL: http://www.w3.org/TR/2000/REC-DOM-Level-2-Core-20001113
[RDFA-SYNTAX]
Steven Pemberton; et al. RDFa in XHTML: Syntax and Processing. 14 October 2008. W3C Recommendation. URL: http://www.w3.org/TR/2008/REC-rdfa-syntax-20081014

B.2 Informative references

No informative references.