Datatyping in RDF/XML


The original RDF Model and Syntax specification states a property value (i.e. the object of a triple) may be denoted by any of the following:

  1. Literal (a simple untyped string that is self-denoting)
  2. Blank node (also known as anonymous nodes)
  3. A URI Reference per (RFC2396)
  4. XML literal (this is a special case of Literal; it is supported syntactically via the rdf:parseType="Literal" attribute/value pair)

Note, however, the Model and Syntax specification and the (2000-03-27) RDF Schema Candidate Recommendation do not provide any direct support for datatyping - that is, they do not define a way to denote datatype values (i.e. no mechanism to state lexical constraints for a property's values). The only loosely-related mechanisms are the rdfs:range and rdfs:domain properties but they are designed to place rdfs:Class constraints on a property and do not provide any semantics for lexical constraints. Note the rdfs:range of rdfs:range is rdfs:Class and not a datatype.

Datatyping Support in RDF

To facilitate datatyping in RDF, the new RDF specifications (see More Information) allow a property value to be a typed literal. A property has a typed literal value if and only if the property element in the RDF/XML has a rdf:datatype attribute. For example a property for a person's age could have a rdf:datatype attribute with a value of something like xsd:nonNegativeInteger. Thus with the new specifications, a property's value may be denoted by any of the values listed above but it may also be denoted by the following:

  1. A typed literal (denotes a datatype value)

Additionally, the Model and Syntax specification is unclear about whether a rdfs:Literal is a sub-class of a rdfs:Resource. The new specifications have clarified this relationship: rdfs:Literal is a sub-class of rdfs:Resource. Consequently, a property's value is always a resource.

Key Concepts

Note the following key concepts regarding datatyping and RDF:

Using XML Schema Datatypes in RDF

The following fragment of RDF/XML shows the usage of XML Schema's nonNegativeInteger datatype for the ex:age property:

 <rdf:Description rdf:about="">
   <ex:age rdf:datatype="">23</ex:age>

There are several important things to note regarding using XML Schema datatypes in RDF/XML:

An application is free to define its own datatypes in any language(s). However, XML Schema is expected to be a popular choice for applications of RDF.

Creating a Datatype Using XML Schema

The following XML Schema fragment defines two datatypes: the Boolean datatype is constrained to strings with the values Yes or No; the Dimension datatype is constrained to a non-negative integer followed by the 'x' character followed by another non-negative integer.

 <xsd:simpleType name="Boolean">
   <xsd:restriction base="xsd:anySimpleType">
     <xsd:enumeration value="Yes"/>
     <xsd:enumeration value="No"/>

 <xsd:simpleType name="Dimension">
   <xsd:restriction base="xsd:anySimpleType">
     <xsd:pattern value="[0-9]+x[0-9]+"/>

The following RDF/XML fragment shows the usage of these two datatypes (assuming the entity reference prf-dt is appropriately defined):

 <ex:SoundEnabled rdf:datatype="&prf-dt;#Boolean">Yes</ex:SoundEnabled>

 <ex:ScreenSize rdf:datatype="&prf-dt;#Dimension">160x160</ex:ScreenSize>

Although it is not a requirement, it is recommended that datatypes created in XML Schema (or any other language) to have rdfs:Datatype statements in the relevant RDF schema. The following RDF schema fragment contains such definitions for the Boolean and Dimension datatypes created above:

 <rdfs:Datatype rdf:about="&prf-dt;Boolean">
   <rdfs:comment xml:lang="en">...</rdfs:comment>
   <rdfs:subClassOf rdf:resource="&xsd;boolean"/>

 <rdfs:Datatype rdf:about="&prf-dt;Dimension">
   <rdfs:comment xml:lang="en">...</rdfs:comment>
   <rdfs:subClassOf rdf:resource="&xsd;anySimpleType"/>

Note that since rdfs:Datatype is a subclass of rdfs:Literal, a plain/untyped literal denotes an instance of rdfs:Literal and not an instance of rdfs:Datatype. The interpretation of untyped literals is fixed - they denote themselves.

If a property definition in a RDF schema contains a rdfs:range property whose rdf:resource attribute value is a datatype and an instance of this property (i.e. a property element in RDF/XML) does NOT contain an appropriate rdf:datatype attribute then the property element's value is considered an untyped literal. A property element MUST contain a rdf:datatype attribute for its value to be a typed literal. This requirement holds even if the property's definition in a schema contains a rdfs:range property whose value is a datatype.

More Information

As of this writing the RDF Core Working Group has published several Working Drafts that contain information about datatyping in RDF. See the following documents and the sections listed for more information:

Last Modified: 2002-12-23
Author: Art Barstow
RDF Resource Description Framework Icon