Given an RDF data graph, and the OWL ontology describing the classes and properties used in this data graph, is there an algorithm, tool, or mapping language that can serialize this data in an XML document corresponding to a target XML schema?
I am thinking about JAXB-like annotations on the ontology classes and properties to drive the XML serialisation.
Typically, given this graph
@prefix data: <http://exemple.fr/data/>
@prefix onto: <http://exemple.fr/ontology.owl#>
data:1 a onto:Work .
data:1 onto:type "book" .
data:1 onto:date "2017-01-01"^^xsd:date .
data:1 onto:has_expression data:2 .
data:2 a onto:Expression .
data:2 onto:language "fr" .
I would like to produce XML similar to the following :
<Work URI="http://exemple.fr/data/1" date="2017-01-01">
<type>book</type>
<Expression URI="http://exemple.fr/data/2">
<lang>fr</lang>
</Expression>
</Work>
Note how this is different from an expected RDF/XML serialisation: a custom attribute holds the URI instead of rdf:about
; some properties are serialized as XML attributes, other as XML elements; onto:has_expression
is not serialized; the element "lang
" is used instead of "language
".
Note that I am looking for "RDF2XML" mapping, and not for an XML2RDF mapping/conversion or an "Object2RDF" mapping.
I could not find anything. I would accept the answer "No, there is no such thing" if others have already searched for this in vain.
There are several options. Of course, you could simply use any programming language for which there is an RDF parser and DOM library and build your XML tree in an ad hoc way.
But the best tool I can think of is XSPARQL, a language that extends XQuery to include SPARQL. With it, you should be able to easily query RDF and generate XML. You can also do the opposite (use XQuery primitives to query XML and generate triples). XSPARQL has been maintained and extended until fairly recently, but it seems nothing new happened in the past two years, as far as I can tell.
Another option is SPARQL template. It's certainly less well known than XSPARQL and may not be as stable. The principle of SPARQL template is that it queries RDF data, and use the results to generate an arbitrary character string. You can thus use it to convert RDF to any format you like, as long as the format has some regularity.
Note that I am not involved in any way in the development of these two technologies. Consider too that they are mostly work of academic researchers, which means that they are not (yet?) at the stage of industry-ready products.