So far, only S-expression is used to represent RDF ontology. It is convenient for lisp programmers to handle pieces of knowledge in RDF. However, SWCLOS, of course, allows users to read RDF/XML format files and print out SWCLOS contents in RDF/XML format.
parse-rdf is a parser for RDF/XML format files. It is useful to check RDF/XML syntax, but it does not interpret anything in semantics. In the following example, you might misunderstand that parse-rdf just prints out an RDF/XML format file, but it is not a reality. parse-rdf produces a list of XML element of lisp structure from RDF/XML file, namely XMLDecl, doctypedecl, Comment, and RDFdecl element as lisp structure. In Common Lisp, the print form of lisp structure is programmable. So, the structure print function of XMLDecl is programmed so as to print out a XMLDecl form in XML, the print function of doctypedecl structure is to “:doctypedecl ...”, a Comment structure to a Comment form, and an RDFdecl structure to an RDFdecl form. In short, parse-rdf reads RDF/XML format file, parses RDF/XML format, makes structures, and returns them in a list. Then, you see RDF/XML-like forms of such structures in the list.
If you want to handle just RDF data without the interpretation of RDFS and OWL from RDF/XML format files, parse-rdf is available to do so. However, in order to interpret contents in RDF/XML files, you may use read-rdf-file with an accepter function, which is usually addRdfXml. See the followings.
gx-user(2):
(with-open-file (p "RDFS/JenaEx.rdf") (parse-rdf p))
(<?xml version="1.0"
?> #<doctypedecl ... >
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#"
xmlns:somewhere="http://somewhere/">
<rdf:Description
rdf:about="http://somewhere/JohnSmith">
<vCard:FN>John
Smith</vCard:FN>
<vCard:N>
<rdf:Description>
<vCard:Family>Smith</vCard:Family>
<vCard:Given>John</vCard:Given>
</rdf:Description>
</vCard:N>
</rdf:Description>
</rdf:RDF>)
gx-user(3):
(read-rdf-file #'addRdfXml "RDFS/JenaEx.rdf")
Warning: Entail by rdf1:
vCard:FN rdf:type rdf:Property.
Warning: Entail by rdf1: vCard:N rdf:type
rdf:Property.
Warning: Entail by rdf1: vCard:Family rdf:type
rdf:Property.
Warning: Entail by rdf1: vCard:Given rdf:type
rdf:Property.
:done
gx-user(4):
somewhere:JohnSmith
#<|rdfs:Resource|
somewhere:JohnSmith>
To print out RDF data in RDF/XML format, the function write-xml is available. See the following example.
gx-user(5):
(write-xml somewhere:JohnSmith)
<rdf:RDF
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:somewhere="http://somewhere/"
xmlns:vCard="http://www.w3.org/2001/vcard-rdf/3.0#"
>
<rdf:Description rdf:about="http://somewhere/JohnSmith"
>
<vCard:FN>John
Smith</vCard:FN>
<vCard:N>
<rdf:Description>
<vCard:Family>Smith</vCard:Family>
<vCard:Given>John</vCard:Given>
</rdf:Description>
</vCard:N>
</rdf:Description>
</rdf:RDF>