3.7 More on RDF Data Types


RDF data types were discussed in Chapter 2, but their impact extends beyond just the RDF abstract model and concepts. RDF data types have their own XML constructs within the RDF/XML specification.

For instance, you can use the xml:lang attribute to specify a language for each RDF/XML element. In the examples in this English-language book, the value would be "en" , and would be included within an element as follows :

 <pstcn:reason xml:lang="en">First in the series</pstcn:reason> 

You can find out more about xml:lang at http://www.w3.org/TR/REC-xml#sec-lang-tag.

You can also specify a general type for a predicate object with rdf:parseType . We've seen rdf:parseType of "Resource" , but you can also use rdf:parseType of "Literal" :

 <pstcn:reason xml:lang="en" rdf:parseType="Literal"><h1>Reason</h1></pstcn:reason> 

By using rdf:parseType="Literal" , you are telling the RDF/XML parser to treat the contents of a predicate as a literal value rather than parse it out for new RDF/XML elements. This allows you to embed XML into an element that is not parsed.

Some implementations of RDF/XML specifically recommend using rdf:parseType="Literal" as a way of including unparsed XML within a document, to bypass having to formalize the XML into an RDF/XML valid syntax. This attribute was never intended to bypass best practices. If the data contained in the attribute is recurring, best practice would be to formalize the XML into RDF/XML and incorporate it into the vocabulary or create a new vocabulary.

RDF also allows for typed literals, which contain a reference to the data type of the literal compatible with the XML Schema data types. In the N3 notation, the typed literal would look similar to the following, as pulled from the RDF Primer:

 ex:index.html  exterms:creation-date  "1999-08-16"^^xsd:date . 

The format of the literal string is value ( 1999-08-16 ), data type URI ( ^^ in this example), and XML Schema data type ( xsd:date ).

As interesting as this format is, one could see how this approach lacks some popularity, primarily because of the intelligence built directly into the string, which can be missed depending on the XML parser that forms the basis of the RDF/XML parser. Luckily, within RDF/XML, the data type is specified as an attribute of the element, using the rdf:datatype attribute, as demonstrated in Example 3-20, which is a copy of Example 3-1, but with data typing added.

Example 3-20. Demonstration of typed literal in RDF/XML
 <?xml version="1.0"?> <rdf:RDF   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"   xmlns:pstcn="http://burningbird.net/postcon/elements/1.0/">   <rdf:Description rdf:about="http://burningbird.net/articles/monsters3.htm">     <pstcn:author rdf:datatype="http://www.w3.org/2001/XMLSchema#string">                                                  Shelley Powers</pstcn:author>     <pstcn:title rdf:datatype="http://www.w3.org/2001/XMLSchema#string">                                                  Architeuthis Dux</pstcn:title>   </rdf:Description> </rdf:RDF> 

There is no requirement to use data types with literals ”it is up to not only the vocabulary designer but also those who generate instances of the vocabulary to decide if they wish to use typed literals. No implicit semantics are attached to typed literals, by which I mean toolmakers are not obliged to double-check the validity of a particular literal against its type. Additionally, there's no requirement that toolmakers even have to differentiate between the types or ensure that typed literals used in an instance map to the same typed literals for the RDF Schema of the vocabulary. Typed literals are more of a way to communicate data types between vocabulary users than between vocabulary-automated processes.

You can read more about XML Schema built-in data types at http://www.w3.org/TR/xmlschema-2/. XML.com also has a number of articles covering XML Schema and data typing in general.



Practical RDF
Practical RDF
ISBN: 0596002637
EAN: 2147483647
Year: 2003
Pages: 131

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net