Copyright © 2010 W3C® (MIT, ERCIM, Keio), All Rights Reserved. W3C liability, trademark and document use rules apply.
A document with RDFa data allow readers to extract semantics or at least structured information about from its content. The extraction of RDFa data bases on RDFa parsers. These parsers return RDFa data either in RDF-like [RDF-PRIMER] or more object-oriented structures. An important use case of RDFa is adding semantics to HTML or XHTML web pages. Browsers that render these documents provide users and developers with basic tool support to read the text content or process it in other ways. A problematic issue with existing RDFa parsers is the tedious integration into current browsers. Language incompatibilities of supported ECMA [ECMA-262] Versions and especially the implementations of ECMA are one reason amongst others.
This document defines an Application Programming Interface (API) for processing RDFa [RDFA-SYNTAX] data on the supposition that RDFa is part of an Document Object Model (DOM) [DOM-LEVEL-3-CORE]. RDFa data inside documents written in languages that are based on a DOM (e.g., SVG [SVGTINY12], XHTML [XHTML-RDFA], or HTML [[HTML+RDFA]]) can be extracted and retrieved by using this RDFa DOM API. The RDFa DOM API is intended to be implemented as browser extension or other forms of software libraries. The specification of the RDFa DOM API provides a uniform programming API for processing RDFa content across different versions and types of browser or other types of document processors.
RDFa is a serialization format of the Resource Description Framework (RDF) [RDF-SYNTAX]. The RDFa DOM API provides methods to extract RDF triples from RDFa content. The RDFa DOM API also provides methods to retrieve document parts that contain certain RDF triples.
This document is a detailed interface specification for an RDFa DOM API, aimed at:
For those looking for an introduction to the use of RDFa and some real-world examples, please consult the RDFa Primer.
This section is non-normative.
First, if you are not familiar with either RDFa or RDF, but want to process RDFa in your documents, then it is recommended to look at the RDFa Primer [RDFA-PRIMER] as short introduction. However, the RDFa DOM API is designed to be used without deep knowledge about RDFa.
If you are already familiar with RDFa, and you want to process RDFa content in documents then you'll find the RDFa DOM API section of most interest. It contains a couple of example Javascript code for each part of the RDFa DOM API.
If you are not familiar with RDFa, but you are familiar with RDF, this document should contains no unknown concepts for you.
If you are not familiar with RDF, then you might want to take a look at the section on RDF Terminology of the RDFa CORE [RDFA-CORE] as short introduction. Although the RDFa DOM API is designed to be easy to develop with — and authors don't need to understand RDFa to use it — anyone consume RDFa content in documents should have at least a basic understanding of RDF.
The specification of the RDFa DOM API is written in the Web Interface Definition Language. If you intend to implement the RDFa DOM API you should hava a look at the Web IDL language [WEBIDL] to understand specifications about interfaces of the RDFa DOM API.
Examples may contain references to existing vocabularies and use abbreviations to refer to these. Such vocabularies and their abbreviations are:
rdf
, e.g., rdf:type
)rdfs
, e.g., rdfs:label
)foaf
, e.g., foaf:name
)The RDFa DOM API uses RDF as underlying data model
[RDF-CONCEPTS]. Therefore, it provides interface definitions for
programming with these RDF Resources: Typed Literals, Plain
Literals, URI References and Blank nodes. You may want
to take a look at the section on RDF Terminology of the RDFa
CORE [RDFA-CORE] as short introduction about these basic types. Typed
Literals, Plain Literals, URI References and Blank
nodes are the components to work with RDFTriples
in the RDFa
DOM API.
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 is an early editors draft for discussion purposes. Once development is complete, if accepted by the W3C membership, this document will be published under http://www.w3.org/TR/2010/TR-rdfa-dom-api
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 (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.
This section is non-normative.
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 an API eith set of interfaces that are capable of finding and extracting RDFa from web pages or other document formats that are based on the Document Object Model (DOM). The RDFa DOM API is designed with ease of use in mind. A deep understanding of RDFa is not necessary in order to extract and utilize the structured data embedded in RDFa documents.
The need for an RDFa DOM API arrises from the fact, that existing incompatibilities in programming with different Browser products and even different versions of the same product complicate platform independent capabilities for processing and finding RDFa content in web pages. The RDFa DOM API provides a uniform and user-friendly interface for consuming RDFa.
Most browser-based applications and browser extensions that utilize HTML documents are written in Javascript [ECMA-262]. For this reason, the design of the RDFa DOM API allows easy implementations in Javascript. However, the RDFa DOM API specification is language independant. Developers may implement it any other programming language (e.g., Python, Java, Perl, or Ruby).
The working group has not reached consensus whether or not the traditional RDF model should be used to express the items returned by the RDFa DOM API, or if a simpler object representation format, such as a Javascript associative Array would be more appropriate for processing RDF data in Javascript. To compromise, in addition to standard RDF resources the interface RDFaObject was created.
In general, RDFa is a special syntax for expressing RDF triple and RDF graphs in documents. For this reason the RDFa DOM API uses RDF as basic data model and provides interface to extract RDF data from RDFa content and process it afterwards.
The basic RDF resource types of the RDFa DOM API are:
"Harry Potter and the Half-Blood
Prince"@en
is a plain literal with an English text value. The literal
value is specified in the Terse RDF Triple Language (TURTLE) [TURTLE]
)"Harry Potter and the Half-Blood
Prince"^^xsd:string
is a typed literal with a value of type xsd:string
.
The literal value is also specified in TURTLE)<http://www.w3.org/2001/XMLSchema#string>
,
the URI value is specified in TURTLE )_:me
, _:42
,
the Blank Nodes' values are specified in TURTLE)The RDFa DOM API leaves it open to developers to re-arrange these RDF resource types in further hierarchical structures.
RDF resources are the components of:
_:123 rdfs:label
"Harry Potter" .
)An RDF Literal is an RDF Resource that represents lexical values in RDFa data. The RDF Literals used in the RDFa DOM API (i.e., PlainLiteral, TypedLiteral) behave like they are defined in RDF [RDF-CONCEPTS]. You may want to have a look into the the definition of literals in an RDF graph.
The RDFa DOM API separates between PlainLiteral and TypedLiteral. 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.
'en'
, 'fr'
,
'de'
).xsd:DateTime
).PlainLiterals have a String value and optionally a language tag as defined in [RDF-CONCEPTS], normalized to lowercase.
[Constructor(in DOMString value), Constructor(in DOMString value, in DOMString language), Constructor(in DOMString value, in DOMString language, in Node element), Stringifies=value]
interface PlainLiteral {
readonly attribute DOMString value;
readonly attribute DOMString language;
readonly attribute Node element;
};
element
of type Node, readonlylanguage
of type DOMString, readonlylanguage
is
set, then the value of type
is a URI
with
value rdf:Literal
value
of type DOMString, readonlyThis section is non-normative.
>> var literal = new PlainLiteral('Harry Potter and the Half-Blood Prince', 'en'); >> print(literal.toString()); Harry Potter and the Half-Blood Prince >> print(literal.value); Harry Potter and the Half-Blood Prince >> print(literal.language); en
Example use of PlainLiteral in Javascript
A TypedLiteral has a String value and a datatype URI being an RDF URI reference. TypedLiterals can be converted into native language datatypes of the implementing programming language(please refer to Type conversion of Typed Literals for more information).
The datatype's URI reference defines the datatype of the text
value, e.g., xsd:DataTime
or xsd:boolean
.
The RDFa DOM API provides a method to explicitly convert TypedRDFLiteral values to native datatypes of the implementing programming language. Developers may write their own TypedLiteralConverters in order to convert an RDFLiteral into a prefered language type. The converters are registered by using the registerTypeConversion() method of the RDFa DOM API. As default standard converters for the following XML Scheme datatypes are provided if a corresponding datatype exists the current programming language:
[Constructor(in DOMString value, in URI type), Constructor(in DOMString value, in URI type, in Node element), Stringifies=value]
interface TypedLiteral {
readonly attribute DOMString value;
readonly attribute URI
type;
readonly attribute Node element;
Any valueOf ();
};
element
of type Node, readonlytype
of type URI
, readonlyvalue
of type DOMString, readonlyvalueOf
Any
This section is non-normative.
>> var literal = new TypedLiteral('2010-12-24', new URI("http://www.w3.org/2001/XMLSchema#date")); >> print(literal.toString()); 2010-12-24 print(literal.value); 2010-12-24 >> print(literal.valueOf()); Fri Dec 24 2010 00:00:00 GMT+0100
Example use of TypedLiteral in Javascript
This callable interface provides a function that concerts the value of a TypedLiteral into a corresponding type of the current programming language.
[Callback]
interface TypedLiteralConverter {
Any convertType (in DOMString value);
};
interface rdfa {
void registerTypeConversion (in URI
type, in TypedLiteralConverter
converter);
};
registerTypeConversion
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
type |
| ✘ | ✘ | An URI reference of the datatype type of the current TypedLiteral |
converter |
| ✘ | ✘ | A function that converts the literal's value into the correct type of the current programming language. |
void
This section is non-normative.
>> rdfa.registerTypeConversion(XSD["boolean"], function(value) {return new Boolean(value);}); >> var literal = new TypedLiteral('1', XSD["boolean"]); >> print(literal.toString()); 1 >> print(literal.value); 1 >> print(literal.valueOf()); true
Example use of TypedLiteralConverters in Javascript
A URI in the RDFa DOM API is a RDF URI reference as specified in RDF Concepts and Abstract Syntax [RDF-CONCEPTS].
[Constructor(in DOMString value), Constructor(in DOMString value, in Node element), Stringifies=value]
interface URI {
readonly attribute DOMString value;
readonly attribute Node element;
};
Processing RDF data involve a frequent use of URI references to
single instances (e.g., http://dbpedia.org/resource/RDFa
) ,
vocabulary properties (e.g., rdf:type
) or classes (e.g., foaf:Person
).
For this reason the RDFa DOM API provides a method to make
handling of commonly used URIs more convenient. The following
vocabularies should be implemented as default in an implementaion of the
RDFa DOM API: RDF and XSD.
interface rdfa {
[NameGetter]
any get (in DOMString prefix);
[NameSetter, NameCreator]
void set (in DOMString prefix);
void setMapping (in DOMString prefix, in DOMString value, in URI
uri);
};
get
foaf
map to http://xmlns.com/foaf/0.1/
). The returned object is
a map that contains named properties for each existing value created by
calling rdfa:setMapping(prefix, value, uri)
. (e.g., the
value name
of a prefix foaf
that maps to http://xmlns.com/foaf/0.1/name
)
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
prefix | DOMString | ✘ | ✘ | The prefix value that identifies a maps that contains named
properties for each existing value created by calling rdfa:setMapping(prefix,
value, uri) . (e.g., let foaf be the name of a map of URIs
in the namespace of http://xmlns.com/foaf/0.1/ . (e.g.,
with a named property Person of value http://xmlns.com/foaf/0.1/Person ) |
any
set
foaf
map to http://xmlns.com/foaf/0.1/
). The passed Object
value is an object that also allows creationof named properties.)
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
prefix | DOMString | ✘ | ✘ | The prefix value that identifies a maps that contains named
properties for each existing value created by calling rdfa:setMapping(prefix,
value, uri) . (e.g., let foaf be the name of a map of URIs
in the namespace of http://xmlns.com/foaf/0.1/ . (e.g.,
with a named property Person of value http://xmlns.com/foaf/0.1/Person ) |
void
setMapping
rdfa.foaf.Person
map to a URI with
value http://xmlns.com/foaf/0.1/Person
). Calling
setMapping with a prefix value that does not exist as named property
results in the creation of such a property with the value of prefix as
name. The value of this property is an object with a property whose
name equals the DOMString passed with value
. The value of
this property is the URI passed with uri
.
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
prefix | DOMString | ✘ | ✘ | The prefix that abbreviates the namespace of uri
(e.g., foaf abbreviates http://xmlns.com/foaf/0.1/
in URI http://xmlns.com/foaf/0.1/Person ) |
value | DOMString | ✘ | ✘ | The value of the URI. (e.g., Person in http://xmlns.com/foaf/0.1/Person ) |
uri |
| ✘ | ✘ | The complete URI reference. |
void
This section is non-normative.
>> var uri = new URI("http://www.example.com") // create a new URI >> print(uri.toString()); // Stringify this URI http://www.example.com >> print(uri.value); // print property value of this URI http://www.example.com >> rdfa.setMapping("foaf", "Person", new URI("http://xmlns.com/foaf/0.1/Person")); // create new URI mapping >> rdfa.setMapping("foaf", "name", new URI("http://xmlns.com/foaf/0.1/name")); // create new URI mapping >> print(rdfa.foaf.Person); // get URI value of foaf:Person as named property of rdfa http://xmlns.com/foaf/0.1/Person >> print(rdfa.foaf.name); // get URI value of foaf:name as named property of rdfa http://xmlns.com/foaf/0.1/name >> print(rdfa.foaf["Person"]); // use bracket syntax to get URI value of foaf:Person as named property of rdfa http://xmlns.com/foaf/0.1/Person >> print(rdfa.foaf["name"]); // use bracket syntax to get URI value of foaf:name as named property of rdfa http://xmlns.com/foaf/0.1/name >> rdfa.foaf = {"knows" : new URI("http://xmlns.com/foaf/0.1/knows")}; // create new URI mapping by setting a named property
Example use of URI in Javascript
A BlankNode
is an anonymous RDF resource as
defined in [RDF-CONCEPTS]. The RDFa DOM API makes no
reference to any internal structure of blank nodes. Therefore, it is not
necessary that serialized Blank Nodes in RDFa preserve the same value in
an implementation of the RDFa DOM API. It has just to be
assured to test if two BlankNodes are the same or not.
[Constructor, Stringifies=value]
interface BlankNode {
readonly attribute DOMString value;
};
value
of type DOMString, readonlyThis section is non-normative.
>> var bn = new BlankNode(); // create a new BlankNode >> print(bn.toString()); // Stringify this BlankNode _:42 >> print(bn.value); // print property value of this BlankNode 42
Example use of a BlankNode in a Javascript implementation that uses running numbers as representation.
In the RDFa DOM API, RDFTriple defines the data structure to represent an RDF triples as specified in [RDF-CONCEPTS]. RDFTriple exposes its properties subject, predicate object either in form of names and in form of indexes. The stringification of RDFTriple results in an N-Triples-based or Turtle-based serialization [TURTLE] of the represented RDF triple.
[Constructor(in URI subject,in URI predicate,in URI object),
Constructor(in URI subject, in URI predicate, in PlainLiteral object),
Constructor(in URI subject, in URI predicate, in TypedLiteral object),
Constructor(in URI subject, in URI predicate, in BlankNode object),
Constructor(in BlankNode subject, in URI predicate, in URI object),
Constructor(in BlankNode subject, in URI predicate, in PlainLiteral object),
Constructor(in BlankNode subject, in URI predicate, in TypedLiteral object),
Constructor(in BlankNode subject, in URI predicate, in BlankNode object),
Stringifies, Null=Null]
interface RDFTriple {
const unsigned short LENGTH = 3;
const unsigned short SUBJECT_INDEX = 0;
const unsigned short PREDICATE_INDEX = 1;
const unsigned short OBJECT_INDEX = 2;
readonly attribute Object subject;
readonly attribute Object predicate;
readonly attribute Object object;
[IndexGetter]
Object getByIndex (in unsigned long index);
};
getByIndex
Parameter | Type | Nullable | Optional | Description | ||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
index | unsigned long | ✘ | ✘ | An index position with a positive integer value less than
three. Index values are mapped to properties:
|
Object
LENGTH
of type unsigned shortOBJECT_INDEX
of type unsigned shortPREDICATE_INDEX
of type unsigned shortSUBJECT_INDEX
of type unsigned shortThis section is non-normative.
>> var triple = new RDFTriple(new URI('http://www.example.com#foo'), rdfa.foaf.name, new PlainLiteral('foo')]); //create a new RDFTriple >> print(triple.subject); // print the property subject of the RDFTriple http://www.example.com#foo >> print(triple[0]); // use the index getter to print the property subject of the RDFTriple http://www.example.com#foo >> print(triple.toString()); // Stringify the RDFTriple http://www.example.com#foo http://www.w3.org/2000/01/rdf-schema#label foo
Example use of RDFTriple in Javascript
The RDFTripleList is a plain list of RDFTriple objects. Besides providing a RDFTripleList:get() method, RDFTripleList exposes its list content in style of arrays.
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
This section is non-normative.
>> var rdfTripleList = rdfa.filter(); // filter all RDF triples from current web page as RDFTripleList >> print(rdfTripleList.length); // print the count of filtered RDF triples 3 >> for(var i=0; i<rdfTripleList.length; i++) { // loop through filtered RDF triples print(rdfTripleList.get(i)); // print RDF triple by using the explicit get method print(rdfTripleList[i]); // print RDF triple by using the indexed property method } http://www.example.com#foo http://www.w3.org/2000/01/rdf-schema#label foo http://www.example.com#foo http://www.w3.org/2000/01/rdf-schema#label foo http://www.example.com#foo http://www.w3.org/2000/01/rdf-schema#label bar http://www.example.com#foo http://www.w3.org/2000/01/rdf-schema#label bar http://www.example.com#foo http://www.w3.org/2000/01/rdf-schema#label foobar http://www.example.com#foo http://www.w3.org/2000/01/rdf-schema#label foobar
The RDFTripleIterator iterates through RDF triples that reside inside RDFa content of Nodes of the DOM tree. Compared to the RDFTripleList using the RDFTripleIterator is less memory consuming, as RDF triples are extracted while iterating.
interface RDFTripleIterator {
readonly attribute Node root;
readonly attribute RDFTripleFilter
filter;
readonly attribute RDFTriple
triplePattern;
RDFTriple
previous ();
RDFTriple
next ();
};
filter
of type RDFTripleFilter
, readonlyroot
of type Node, readonlytriplePattern
of type RDFTriple
, readonlynext
RDFTriple
previous
RDFTriple
This section is non-normative.
>> var iter = rdfa.iterate(); // filter all RDF triples from current web page as RDFTripleIterator >> for(var triple = iter.next(); iter != null; triple = iter.next()) { // step through all RDF triples print(triple); // print current RDF triple } http://www.example.com#foo http://www.w3.org/2000/01/rdf-schema#label foo http://www.example.com#foo http://www.w3.org/2000/01/rdf-schema#label bar http://www.example.com#foo http://www.w3.org/2000/01/rdf-schema#label foobar
The interface RDFTripleProjection provides a projection of all RDF triples in a document about a single subject. Furthermore the RDFTripleProjection aggregates these RDF triples as a single object. Predicate-object pairs of the existing RDF triples are projected to named properties of the created object.
RDFTripleProjection provides an user-friendly interface for getting all information bout a single subject in single object.
interface RDFTripleProjection {
readonly attribute URI
subject;
readonly attribute Sequence[URI] properties;
[NameGetter]
Sequence[any] get (in DOMString name);
};
properties
of type Sequence[URI], readonlysubject
of type URI
, readonlyget
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
name | DOMString | ✘ | ✘ | The DOMString value of name equals the String representation of the projected predicate values of aggregated RDF triples. |
Sequence[any]
This section is non-normative.
>> var subject = new URI("http://www.ivan-herman.net/foaf#me"); // create URI for subject >> var myRdfaObject = rdfa.extractObject(subject); // extract information about this subject as RDFTripleProjection from a web page >> print(myRdfaObject.subject); // print the subject of this RDFTripleProjection http://www.ivan-herman.net/foaf#me >> print(myRdfaObject.properties); // print all projected property names http://xmlns.com/foaf/0.1/name, http://xmlns.com/foaf/0.1/title, http://xmlns.com/foaf/0.1/surname, http://xmlns.com/foaf/0.1/givenname, http://xmlns.com/foaf/0.1/workInfoHomepage >> print(myRdfaObject[rdfa.foaf.name]); // print named property values of foaf:name Herman Iván, Ivan Herman >> print(myRdfaObject[rdfa.foaf.title]); // print named property values of foaf:title Dr. >> print(myRdfaObject[rdfa.foaf.workInfoHomepage]); // print named property values of foaf:workInfoHomepage http://www.iswsa.org/, http://www.iw3c2.org, http://www.w3.org/2001/sw/#activity
The RDFa DOM API strives to be a simple set of methods that a developer may use to retrieve RDF triples and document parts containing these in a document.
The key mechanism for extracting either RDF data from DOM elements or DOM elements with RDFa content focuses on the use of filters. Filters are used to select RDF triple data as well as elements that are contained in the document.
Finally, the following methods of 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.
interface rdfa {
const DOMString VERSION = "0.1";
};
VERSION
of type DOMStringThe core interface of the RDFa DOM API provides a list of methods for filtering. It destincts between filtering RDF triples as RDFTripleList, and filtering RDF triples as RDFTripleIterator.
interface rdfa {
[Null=Null]
RDFTripleList
filter ([Variadic] in Object? subject, in URI
? predicate, in Object? object, in Node? element, in RDFTripleFilter
? myfilter);
[Null=Null]
RDFTripleIterator
iterate ([Variadic] in Object? subject, in URI
? predicate, in Object? object, in Node? element, in RDFTripleFilter
? myfilter);
RDFTripleProjection
project (in URI
subject);
};
filter
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
subject | Object | ✔ | ✘ | Subject pattern of an RDF triple that should be tested. Values can be of type URI, BlankNode, or Null. If subject is set to null, the filter does not consider subject values to deciding whether an RDFTriple is added to the result list or not. |
predicate |
| ✔ | ✘ | Predicate pattern of an RDF triple that should be tested. If predicate is set to null, the filter does not consider predicate values to deciding whether an RDFTriple is added to the result list or not. |
object | Object | ✔ | ✘ | Object pattern of an RDF triple that should be tested. Values can be of type URI, BlankNode, TypedLiteral, PlainLiteral or Null. If object is set to null, the filter does not consider object values to deciding whether an RDFTriple is added to the result list or not. |
element | Node | ✔ | ✘ | The part a the DOM tree with element as root that should be filtered for RDF triples. |
myfilter |
| ✔ | ✘ | A user defined boolean function for deciding whether an RDFTriple is added to the result list or not. |
RDFTripleList
iterate
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
subject | Object | ✔ | ✘ | Subject pattern of an RDF triple that should be tested. Values can be of type URI, BlankNode, or Null. If subject is set to null, the filter does not consider subject values to deciding whether an RDFTriple is added to the result list or not. |
predicate |
| ✔ | ✘ | Predicate pattern of an RDF triple that should be tested. If predicate is set to null, the filter does not consider predicate values to deciding whether an RDFTriple is added to the result list or not. |
object | Object | ✔ | ✘ | Object pattern of an RDF triple that should be tested. Values can be of type URI, BlankNode, TypedLiteral, PlainLiteral or Null. If object is set to null, the filter does not consider object values to deciding whether an RDFTriple is added to the result list or not. |
element | Node | ✔ | ✘ | The part a the DOM tree with element as root that should be filtered for RDF triples. |
myfilter |
| ✔ | ✘ | A user defined boolean function for deciding whether an RDFTriple is added to the result list or not. |
RDFTripleIterator
project
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
subject |
| ✘ | ✘ | The subject to collect infromation about. |
RDFTripleProjection
Filter criterias can also be user-defined as RDFTripleFilter
by developers. These callable functions check if an RDFTriple should be
inserted into a resulting list or iterator.
[Callback, Null=Null]
interface RDFTripleFilter {
boolean match ([Variadic] in Node? element, in Object? subject, in URI
? predicate, in Object? object);
};
match
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
element | Node | ✔ | ✘ | The part a the DOM tree with element as root that should be filtered for RDF triples. |
subject | Object | ✔ | ✘ | Subject pattern of an RDF triple that should be tested. Values can be of type URI, BlankNode, or Null. If subject is set to null, the filter does not consider subject values to deciding whether an RDFTriple is added to the result list or not. |
predicate |
| ✔ | ✘ | Predicate pattern of an RDF triple that should be tested. If predicate is set to null, the filter does not consider predicate values to deciding whether an RDFTriple is added to the result list or not. |
object | Object | ✔ | ✘ | Object pattern of an RDF triple that should be tested. Values can be of type URI, BlankNode, TypedLiteral, PlainLiteral or Null. If object is set to null, the filter does not consider object values to deciding whether an RDFTriple is added to the result list or not. |
boolean
This section is non-normative.
The following examples refer to this HTML code
<div id="start" about="http://dbpedia.org/resource/Albert_Einstein"> <span property="foaf:name">Albert Einstein</span> <span property="dbp:dateOfBirth" datatype="xsd:date">1879-03-14</span> <div rel="dbp:birthPlace" resource="http://dbpedia.org/resource/Germany"> <span class="hilite"><span property="dbp:conventionalLongName">Federal Republic of Germany</span></span> </div> </div>
Example use of rdfa.filter and rdfa.iterate in Javascript
>> var myFilter = new function(element, subject, predicate, object) { // create a filter function that filter if(subject.value.search(/http:\/\/xmlns.com\/foaf\/0\.1/) >= 0) { // for triples with predicates in the foaf namespace. return true; } } >> var tripleList = rdfa.filter(null, null, null, document.getElementById("start"), myFilter); // start filtering at element with id=start >> for(var i=0; i < tripleList.length; i++) { print(tripleList[i]) } <http://dbpedia.org/resource/Albert_Einstein> <http://xmlns.com/foaf/0.1/name> "Albert Einstein" >> var iter = rdfa.iterate(null, null, null, document.getElementById("start"), myFilter); // start filtering by iterating at element with id=start >> for(var triple=iter.next(); triple != null; triple = iter.next()) { print(triple) } <http://dbpedia.org/resource/Albert_Einstein> <http://xmlns.com/foaf/0.1/name> "Albert Einstein"
Example use of rdfa.project in Javascript
>> var einstein = rdfa.project(new URI("http://dbpedia.org/resource/Albert_Einstein")); >> print(einstein.properties); http://xmlns.com/foaf/0.1/name, http://dbpedia.org/property/dateOfBirth, http://dbpedia.org/property/birthPlace, http://dbpedia.org/property/conventionalLongName >> print(einstein[rdfa.dbp.dateOfBirth]); 1879-03-14 >> print(einstein[rdfa.dbp.birthPlace]); http://dbpedia.org/resource/Germany
In addition to filter RDF triples from RDFa content, the RDFa DOM API also provides methods for filtering DOM elements that contain specific RDFa data.
interface rdfa {
NodeList getElements ([Variadic] in Object? subject, in URI
? predicate, in Object? object, in RDFTripleFilter
? myfilter);
boolean containsRDFa ([Variadic] in Node? element, in Object? subject, in URI
? predicate, in Object? object, in RDFTripleFilter
? myfilter);
};
containsRDFa
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
element | Node | ✔ | ✘ | The part a the DOM tree with element as root that should be filtered for RDF triples. |
subject | Object | ✔ | ✘ | Subject pattern of an RDF triple that should be tested. Values can be of type URI, BlankNode, or Null. If subject is set to null, the filter does not consider subject values to deciding whether an RDFTriple is added to the result list or not. |
predicate |
| ✔ | ✘ | Predicate pattern of an RDF triple that should be tested. If predicate is set to null, the filter does not consider predicate values to deciding whether an RDFTriple is added to the result list or not. |
object | Object | ✔ | ✘ | Object pattern of an RDF triple that should be tested. Values can be of type URI, BlankNode, TypedLiteral, PlainLiteral or Null. If object is set to null, the filter does not consider object values to deciding whether an RDFTriple is added to the result list or not. |
myfilter |
| ✔ | ✘ | A user defined boolean function for deciding whether an RDFTriple is added to the result list or not. |
boolean
getElements
Parameter | Type | Nullable | Optional | Description |
---|---|---|---|---|
subject | Object | ✔ | ✘ | Subject pattern of an RDF triple that should be tested. Values can be of type URI, BlankNode, or Null. If subject is set to null, the filter does not consider subject values to deciding whether an RDFTriple is added to the result list or not. |
predicate |
| ✔ | ✘ | Predicate pattern of an RDF triple that should be tested. If predicate is set to null, the filter does not consider predicate values to deciding whether an RDFTriple is added to the result list or not. |
object | Object | ✔ | ✘ | Object pattern of an RDF triple that should be tested. Values can be of type URI, BlankNode, TypedLiteral, PlainLiteral or Null. If object is set to null, the filter does not consider object values to deciding whether an RDFTriple is added to the result list or not. |
myfilter |
| ✔ | ✘ | A user defined boolean function for deciding whether an RDFTriple is added to the result list or not. |
NodeList
This section is non-normative.
The following examples refer to this HTML code
<div id="start" about="http://dbpedia.org/resource/Albert_Einstein"> <span property="foaf:name">Albert Einstein</span> <span property="dbp:dateOfBirth" datatype="xsd:date">1879-03-14</span> <div rel="dbp:birthPlace" resource="http://dbpedia.org/resource/Germany"> <span class="hilite"><span property="dbp:conventionalLongName">Federal Republic of Germany</span></span> </div> </div>
Example use of rdfa.containsRDFa and rdfa.getElements in Javascript
>> var germany = new URI("http://dbpedia.org/resource/Germany") >> print(rdfa.containsRDFa(document.getElementById("start"), null, null, germany))); // lookup if html contains RDFa about Germany true >> var myFilter = new function(element, subject, predicate, object) { // create a filter function that filter if(subject.value.search(/http:\/\/xmlns.com\/foaf\/0\.1/) >= 0) { // for triples with predicates in the foaf namespace. return true; } } >> var nodelist = rdfa.getElements(null, null, null, myFilter); // filter DOM elements for foaf statements >> print(nodelist.length); 1
This section is non-normative.
The current version of the RDFa DOM API focusses on filtering RDF triples. It also provides methods for filtering DOM nodes that contain certain types of RDF triples.
The RDFa Working Group discusses about additional functionalities such as:
At the time of publication, the members of the RDFa Working Group were:
This document contains the Web IDL definitions of the RDFa DOM API: rdfa_dom_api.idl
This document contains the Javascript Conversion of the RDFa DOM API:rdfa_dom_api.js
The API documentation of the Javascript Conversion is provided here: JSDoc API