title: An Introduction to RDF and the Jena RDF API

This is a tutorial introduction to both W3C's Resource Description Framework (RDF) and Jena, a Java API for RDF. It is written for the programmer who is unfamiliar with RDF and who learns best by prototyping, or, for other reasons, wishes to move quickly to implementation. Some familiarity with both XML and Java is assumed.

In the previous section, we saw that the output XML declared a namespace prefix vcard and used that prefix to abbreviate URIs. While RDF uses only the full URIs, and not this shortened form, Jena provides ways of controlling the namespaces used on output with its prefix mappings. Here's a simple example.

The output from this fragment is three lots of RDF/XML, with three different prefix mappings. First the default, with no prefixes other than the standard ones:

We see that the rdf namespace is declared automatically, since it is required for tags such as <rdf:RDF> and <rdf:resource>. XML namespace declarations are also needed for using the two properties P and Q, but since their prefixes have not been introduced to the model in this example, they get invented namespace names: j.0 and j.1.

The other namespace still gets the constructed name, but the nsA name is now used in the property tags. There's no need for the prefix name to have anything to do with the variables in the Jena code:

Both prefixes are used for output, and no generated prefixes are needed.

As well as prefix declarations provided by calls to setNsPrefix, Jena will remember the prefixes that were used in input to model.read().

You‘ll see that the prefixes from the input are preserved in the output. All the prefixes are written, even if they’re not used anywhere. You can remove a prefix with removeNsPrefix(String prefix) if you don't want it in the output.

listStatements( S, P, O )

is equivalent to

listStatements( new SimpleSelector( S, P, O ) )