Copyright © 2010 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
This specification defines an Application Programming Interface (API) for accessing RDFa[RDFA-SYNTAX] data contained in the Document Object Model (DOM) of a structured document, such as SVG, XHTML or HTML. The so called RDFa DOM API can be used to extract specific RDF triples from DOM nodes that contain RDFa. Vice versa, the RDFa DOM API provides methods to retrieve specific DOM nodes that contain specific RDF triple patterns inside existing RDFa content.
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 Working Group as an Editor's Draft. If you wish to make comments regarding this document, please send them to public-rdfa-wg@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.
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 RDFa data expressed by a document and then make programmatic decisions based on the semantic data embedded in the page.
The RDFa DOM API strives to be a simple set of calls that a developer may
use to retrieve triples contained in the document. It is an extension of the
existing DOM specification [DOM-LEVEL-1].
The key design issue of the RDFa DOM API is built on using filters for
retrieving RDF triples from DOM nodes or retrieving DOM nodes with RDFa content.
Therefore it first defines a set of basic types.
These types (i.e., RDF Resource, RDF Literal, RDF Node, URI Reference,
and Blank node) extend the DOM API in order to program with RDF triples.
For retrieving RDF triples from DOM nodes, the RDFa DOM API makes use of so
called RDFTripleFilters
. Inspired by NodeFilters
in
the DOM specification, RDFTripleFilters
can be user defined and
provide a high flexibility in filtering RDF triples for application programmers.
For conveinience reasons, the RDFa DOM API provides a set of predefined
RDFTripleFilters
(i.e.,RDF_OBJECT_IS_LITERAL, RDF_OBJECT_IS_URI,
RDF_PREDICATE_IS_TYPE) that cover the main use cases in retrieving RDF
from RDFa.
In order to retrieve DOM nodes that contain certain RDFa content, the RDFa DOM
API extended the w3c:dom:Node
interface with a lookup method called
containsRDFa()
. An RDFTripleFilters
can be passed as
optional parameter in order to test DOM nodes for certain RDF triples.
The basic types of the RDFa DOM API are DOMString
, and a hierarchy
starting with RDF Resource
with its descendants: RDF Literal
, RDF Node
, URI
Reference
, and Blank Node
.
The hierarchy is defined as follows:
RDF Resource
RDF Literal
RDF Node
URI Reference
Blank Node
interface RDFResource {
RDFLiteral
createLiteral (in DOMString value, in optional DOMString language);
RDFLiteral
createLiteral (in DOMString value, in URI
type);
URI
createURI (in DOMString value);
URI
createURI (in DOMString namespace, in DOMString suffix);
BlankNode
createBlankNode (in DOMString id);
};
createBlankNode
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
id | DOMString | ✘ | ✘ | The identifier of the blank node. |
BlankNode
createLiteral
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
value | DOMString | ✘ | ✘ | The lexical value of this literal encoded in the character encoding of the source document. |
language | DOMString | ✘ | ✔ | A two characters long language tag as defined by [RFC-3066], normalized to lowercase. |
RDFLiteral
createLiteral
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
value | DOMString | ✘ | ✘ | The lexical value of this literal encoded in the character encoding of the source document. |
type |
| ✘ | ✘ | A datatype identified by an URI reference. |
RDFLiteral
createURI
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
value | DOMString | ✘ | ✘ | The lexical value of this URI. |
URI
createURI
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
namespace | DOMString | ✘ | ✘ | The namespace component of the URI's lexical representation. |
suffix | DOMString | ✘ | ✘ | The suffix component of the URI's lexical representation. |
URI
An RDF Literal
represents lexical values being defined in RDFa
data. In RDF, literals may be attached with language information about the
given text given as language tag, or a datatype given as URI reference. The
language tag is an identifier for a certain language as defined by [RFC-3066].
The datatype's URI reference defines the datatype of the text value, e.g.,
xsd:DataTime
or xsd:boolean
. According to the RDF
specification, for a given RDF Literal
, either language or type
information can be given. If the type is set, the RDF Literal
conforms to the RDF specification of Typed Literal
in
[RDF-CONCEPTS]. Otherwise it conforms to be a Plain Literal
.
interface RDFLiteral : RDFResource
{
readonly attribute DOMString value;
readonly attribute DOMString language;
readonly attribute URI
type;
};
language
of type DOMString, readonlylanguage
is set, then the value of type
is a URI
with value rdf:Literal
type
of type URI
, readonlyvalue
of type DOMString, readonlyURI
and BlankNode
.
interface RDFNode : RDFResource
{
};
interface URI : RDFNode
{
readonly attribute DOMString value;
readonly attribute DOMString namespace;
};
BlankNode
is an anonymous RDFNode
as defined in [RDF-CONCEPTS].
For comparing two BlankNodes
an identifier is used.
Two BlankNodes
are the same if the their identifiers equal on character level.
interface BlankNode : RDFNode
{
readonly attribute DOMString id;
};
id
of type DOMString, readonlyIn the RDFa DOM API, RDFTriple defines the data structure to represent an RDF triples as specified in [RDF-CONCEPTS]. The RDFa DOM API is intended to extract RDFTriple objects from the source document.
interface RDFTriple {
readonly attribute RDFNode
subject;
readonly attribute URI
predicate;
readonly attribute RDFResource
object;
readonly attribute URI
context;
RDFTriple
createTriple (in RDFNode
? subject, in URI
? predicate, in RDFResource
? object);
};
context
of type URI
, readonlyobject
of type RDFResource
, readonlypredicate
of type URI
, readonlysubject
of type RDFNode
, readonlycreateTriple
null
the RDFTriple is concerned to be used as triple patterns in an RDFTripleFilter
.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
subject |
| ✔ | ✘ | Subject value of the RDFTriple. |
predicate |
| ✔ | ✘ | Predicate value of the RDFTriple. |
object |
| ✔ | ✘ | Object value of the RDFTriple. |
RDFTriple
The RDFTripleList is a plain list of RDFTriple objects.
interface RDFTripleList {
readonly attribute unsigned long length;
RDFTriple
get (in unsigned long index);
};
length
of type unsigned long, readonlyget
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
index | unsigned long | ✘ | ✘ | A positive integer value less than RDFTripleList::length that represents an index inside the RDFTripleList |
RDFTriple
The RDFTripleIterator is an Iterator through RDFa content inside Nodes of the DOM tree.
interface RDFTripleIterator {
readonly attribute Node
root;
readonly attribute RDFTripleFilter
filter;
RDFTriple
previousRDFTriple ();
RDFTriple
nextRDFTriple ();
RDFTripleIterator
createRDFTripleIterator (in Node
root, in RDFTripleFilter
filter);
};
filter
of type RDFTripleFilter
, readonlyroot
of type Node
, readonlycreateRDFTripleIterator
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
root |
| ✘ | ✘ | The Node inside the DOM Tree taken as root node to start from the extraction of RDFa content. |
filter |
| ✘ | ✘ | An RDFTripleFilter object that filters the Node objects in the subtree for certain RDFa content. |
RDFTripleIterator
nextRDFTriple
RDFTriple
previousRDFTriple
RDFTriple
The RDFa DOM API provides this RDF filter for testing RDFTriple for certain conditions.
These conditions can be implemented by application developers.
An RDFTripleFilter
may be created with a default RDF triple used as dynamic filter pattern.
E.g., if an RDFTripleFilter
is specified to filter all RDF triples with rdfs:label
as predicate,
the developer might want to use this filter to search for labels of instances of rdf:type
foaf:Person
and foaf:Organisation
. Therefore he creates the RDF triple patterns (null, rdf:type, foaf:Person)
and
(null, rdf:type, foaf:Organisation)
and passes them to his predefined filter instead of writing additonal two filters.
The RDFa DOM API predefines a bunch of static RDFTripleFilter objects for common RDF queries:
interface RDFTripleFilter {
boolean acceptRDFTriple (in RDFTriple
triple, in optional RDFTriple
pattern);
};
acceptRDFTriple
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
triple |
| ✘ | ✘ | The RDF triple that should be tested. |
pattern |
| ✘ | ✔ | The RDF triple pattern given as paramater that should be also tested. |
boolean
This is an extension of w3c:org:dom::Document. It adds one function to retrieve RDF data from web pages.
interface Document {
readonly attribute RDFTripleFilter
RDF_PREDICATE_IS_TYPE;
readonly attribute RDFTripleFilter
RDF_OBJECT_IS_LITERAL;
readonly attribute RDFTripleFilter
RDF_OBJECT_IS_URI;
RDFTripleList
getRDFTriples (in optional RDFTripleFilter
filter);
};
RDF_OBJECT_IS_LITERAL
of type RDFTripleFilter
, readonlyT.object typeof RDFLiteral
RDF_OBJECT_IS_URI
of type RDFTripleFilter
, readonlyT.object typeof URI
RDF_PREDICATE_IS_TYPE
of type RDFTripleFilter
, readonlyT.predicate = RDF.type
getRDFTriples
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
filter |
| ✘ | ✔ | An RDFTripleFilter object that filters the Node objects in the DOM tree for certain RDFa content. |
RDFTripleList
This is an extension of DOM::Node specification. It add two methods, one for testing if RDFa content can be extracted from a Node, the other for extracting this content as RDFTripleList.
interface Node {
boolean containsRDFa (in optional RDFTripleFilter
filter);
};
containsRDFa
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
filter |
| ✘ | ✔ | This optional RDFTripleFilter can be used to test for certain kinds of RDFa content. |
boolean
This section will contain best practices on storing and retrieving triples on a page.
This document has been prepared with the help of the following people (in alphabetical order):
No informative references.