SimpleRdfXml

From W3C Wiki
Revision as of 05:27, 19 October 2007 by LeoSauermann (Talk)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

SimpleRdfXml

Using the general RDF/XML spec, the RDF serialization can look quite different depending on rdf-writer implementation. These diversity in writing RDF makes writing XSLT transformation a black art. What happens is that the data shows up in so many different ways, that many people write big hacks to get it work.

Solution: a simple RDF/XML syntax that is RDF/XML compatible but has some restrictions to it. It is kind-of deterministic and can be better parsed in XSLT. I [LeoS] call it SimpleRdfXml.

See Also

Example

This is a fragment of FOAF, using the simpleRDF/XML

 foaf-example:
 <rdf:RDF
    xmlns:foaf="http://xmlns.com/foaf/0.1/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
    xmlns:owl="http://www.w3.org/2002/07/owl#"
    xmlns:vs="http://www.w3.org/2003/06/sw-vocab-status/ns#"
    xmlns:wot="http://xmlns.com/wot/0.1/"
    xmlns:dc="http://purl.org/dc/elements/1.1/" >
  <rdf:Description rdf:about="http://xmlns.com/foaf/0.1/firstName">
    <rdf:type rdf:resource="http://www.w3.org/1999/02/22-rdf-syntax-ns#Property"/>
    <vs:term_status>testing</vs:term_status>
    <rdfs:label>firstName</rdfs:label>
    <rdfs:comment>The first name of a person.</rdfs:comment>
    <rdf:type rdf:resource="http://www.w3.org/2002/07/owl#DatatypeProperty"/>
    <rdfs:domain rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
    <rdfs:range rdf:resource="http://www.w3.org/2000/01/rdf-schema#Literal"/>
    <rdfs:isDefinedBy rdf:resource="http://xmlns.com/foaf/0.1/"/>
  </rdf:Description>
</rdf:RDF>


Design Rules of SimpleRdfXml

  1. be compatible with RDF/XML
  2. but only a subset
  3. restrict to simplicity

Rules

  1. no nested elements (references to resources must be done via rdf:resource)
  2. all literals as XML nodes <foaf:name>Hello!</foaf:name> and not XML attributes <blub foaf:name="Hello!">
  3. Blank nodes must be identified via rdf:nodeID, the abbreviation with rdf:parseType="Resource" is discouraged.
  4. only full uris, no relative
  5. Type always as rdf:type triple, not as the name of the XML element
  6. Gather all triples of a resource to one element

Changenotes

The blank nodes rule was relaxed, before 19.10.2007 we required that blank nodes must be replaced with URIs. But that would break the standard.

Implementations

Using Jena, the easiest way to get it is:

simple rdf:
Model m = ...;
m.write(System.out, "RDF/XML");

bad rdf:
m.write(System.out, "RDF/XML-ABBREV");


more detail

No nested stuff

All literals as elements, not attributes

Querying from XSLT is easy with both, but having to check both all the time sucks. Most hackers go with the element solution, as it can contain datatypes and languages and can have better strings with CDATA elements.

Full URIS

In foaf-vocab, there is a uri called "../sig" which is the show-stopper. don't do it

Type always as triple

Wrong: <foaf:Person rdf:about="urn:example"> Right:

<rdf:Description rdf:about="urn:example">
  <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>


When things have two types, this comes in handy. Again, a step for making it simpler. (I feel this constraint makes it a lot harder for humans to read, so I don't know if that's the right kind of simplicity KjetilKjernsmo)

Gather all triples of a resource

Wrong:
<rdf:Description rdf:about="urn:example">
  <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
</rdf:Description>
<rdf:Description rdf:about="urn:example">
  <rdfs:label>blub</rdfs:label>
</rdf:Description>

Right
<rdf:Description rdf:about="urn:example">
  <rdf:type rdf:resource="http://xmlns.com/foaf/0.1/Person"/>
  <rdfs:label>blub</rdfs:label>
</rdf:Description>


Contra-Example

This RDF is BAD RDF and is not simple, it breaks the rules: nono:

<foaf:Person rdfs:label="blub">
  <rdfs:commment>asdafsd</rrr>
  <rdf:hasblub >
     <rdf:descrip....