I saved and generated these RDFs using the Jena API, and it came out as follows.
<?xml version="1.0" encoding="UTF-8"?>
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#"
xml:base="urn:uuid:">
<rdfs:Class rdf:about="http://example.org/Animal"/>
<rdfs:Class rdf:about="http://example.org/Cat">
<rdfs:subClassOf rdf:resource="http://example.org/Animal"/>
</rdfs:Class>
<rdfs:Class rdf:about="http://example.org/Dog">
<rdfs:subClassOf rdf:resource="http://example.org/Animal"/>
</rdfs:Class>
</rdf:RDF>
Used Jena API and result
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#">
<rdfs:Class rdf:about="http://example.org/Dog">
<rdfs:subClassOf>
<rdfs:Class rdf:about="http://example.org/Animal"/>
</rdfs:subClassOf>
</rdfs:Class>
<rdfs:Class rdf:about="http://example.org/Cat">
<rdfs:subClassOf rdf:resource="http://example.org/Animal"/>
</rdfs:Class>
</rdf:RDF>
I understand that rdf:resource can be rephrased as rdf:about. But why was rdfs:Classrdf:about="http://example.org/Animal"/ omitted?
Also, what is expressed as rdf:resource and what is expressed as rdf:about?
Yes, semantically, these two RDF/XML files serialize the same RDF. You can verify this for example by converting them to N-Triples, e.g. with Jena’s riot
command-line tool:
riot --syntax=rdfxml --out=ntriples rdf.xml > rdf.nt
Both RDF/XML files will convert to (after sorting):
<http://example.org/Animal> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
<http://example.org/Cat> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
<http://example.org/Cat> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://example.org/Animal> .
<http://example.org/Dog> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://www.w3.org/2000/01/rdf-schema#Class> .
<http://example.org/Dog> <http://www.w3.org/2000/01/rdf-schema#subClassOf> <http://example.org/Animal> .
But why was
<rdfs:Class rdf:about="http://example.org/Animal"/>
omitted?
It exists in both files. In the second file, it’s nested in an <rdfs:subClassOf>
element. RDF/XML allows for many such variations.
what is expressed as
rdf:resource
and what is expressed asrdf:about
?
The rdf:resource
attribute allows for a shorter representation, but can only be used in certain cases. See Empty Property Elements in the spec:
When a predicate arc in an RDF graph points to an object node which has no further predicate arcs, which appears in RDF/XML as an empty node element
<rdf:Description rdf:about="..."> </rdf:Description>
(or<rdf:Description rdf:about="..." />
) this form can be shortened. This is done by using the IRI of the object node as the value of an XML attributerdf:resource
on the containing property element and making the property element empty.
NB: Unless you have to use RDF/XML, I would recommend using an RDF serialization like Turtle. It’s way easier to read/understand.