RDF2XML: Exporting RDF Data to XML (or to RDF)
The common export functionality of RDF data as RDF/XML
(including the Striped RDF/XML variant) results in some
RDF/XML serialization of a (base) graph. It does not allow
to specify a target DTD structure, or to restruct to a graph fragment or
certain properties.
The RDF2XML tool allows a controlled export of RDF data:
- export the whole graph to Striped RDF/XML according to a given target DTD,
- export the whole graph to plain XML according to a given target DTD,
- export only a specified a fragment of a graph to Striped RDF/XML,
- export certain properties/classes (including derived ones under some
entailment regime, e.g., OWL) of the whole graph, or only of a fragment of it.
The method is as follows: Export of the graph is done by a controlled depth-first
traversal.
- provide a Striped DTD, i.e., a DTD that specifies the types and order of
subelements to be generated (i.e., of the properties to be followed and their
relevant result types). The output is a striped RDF/XML document.
- provide a Stripped DTD, i.e., a DTD that is specified a
projection from the obtained striped tree to a reduced DTD.
This step must not change the structure of the tree, but is allowed to omit
intermediate elements, and to turn subelements into attributes (including
the transformation of <x rdf:resource="uri"/> elements into IDREF/IDREFS
attributes).
RDF2XML is experimental.
Common Usage:
RDF2XML as command line tool takes the following parameters:
java -jar rdf2xml.jar <input-rdf> <meta-rdf>
<root node URI> <namespace uri>
<striped-dtd-url> <stripped-dtd-url>
[-of <output-file-name>]
- arg[0]: an RDF graph (in N3 or RDF/XML format)
- arg[1]: another RDF file (in N3 or RDF/XML format;
intended for having separate metadata file, if not applicable
just use again arg[0])
- arg[2]: URI of the root node (should be a URI that exists in the RDF input)
- arg[3]: URI of the language (= its prefix) used in the exported RDF file
- arg[4]: URI of the striped DTD (http:... or file:...)
- arg[5]: URI of the stripped DTD (if not applicable: use again arg[4])
- optionally: -of output-file-name
Example: the example is based on the Mondial
database.
Sample calls:
java -jar ../rdf2xml.jar germany.n3 mondial-meta.n3
http://www.semwebtech.org/mondial/10/countries/D/
http://www.semwebtech.org/mondial/10/meta#
file:mondial-striped.dtd [file:mondial-stripped.dtd]
[-of bla.xml]
java -jar ../rdf2xml.jar mondial-europe.n3 export-germany.n3
http://www.semwebtech.org/mondial/10/meta#relevantMondial
http://www.semwebtech.org/mondial/10/meta#
file:mondial-striped.dtd file:mondial-stripped.dtd
-of bla.xml
(the latter may take some time - depending on the computer 1-3 hours. This is not
specific to rdf2xml, but any application involving a reasoner and the rather large ABox
of Mondial takes time)
Usage in MARS:
RDF2XML has been implemented mainly as it is needed in the MARS
framework for transforming rules in RDF representation into XML markup
(which can then be processed by the ECA engine). There, it is used as an
embedded Java class.
Nevertheless, for development and demos, there is a command line
interface tailored to MARS (i.e., when using MARS languages that are
listed with their DTDs in the LSR (Languages and Services Registry)).
It works only when your computer has internet connection, as it must
access the online LSR.
java -jar rdf2xml.jar <rdf input filename> <root node URI>
[<startLangURI> [<stripedDTDURI> [<strippedDTDURI>]]]
- Download mars-test.zip,
unzip it. It contains sample RDF rules; the LSR and the DTDs are accessed online.
Sample call
java -jar ../rdf2xml.jar <some-of-the-rdf-rule-files.rdf> foo://bla/theRule