I need to create RDF that looks like this:
<rdf:Description rdf:about='uri1'>
<namespace:level1>
<rdf:Description>
<namespace:blankNode rdf:resource='uri2'/>
<namespace:text></namespace:text>
</rdf:Description>
</namespace:level1>
</rdf:Description>
<rdf:Description rdf:about="uri2">
some properties here
</rdf:Description>
As you can see, there are nested structures, as well as blank nodes. (I don't know if that's the exact terminology for the "blankNode" property in my structure.) If I use
model.write(System.out, "RDF/XML-ABBREV");
then even the blank node is nested, which I don't want. Is there any way to get this kind of structure using Jena? Or is there any other library for Java that can handle this better?
Meanwhile in RDF4J, I have a found the
org.eclipse.rdf4j.rio.rdfxml.util.RDFXMLPrettyWriter
to do exactly what I want, produces a nice nested clean and compact RDFXML document of a nested configuration.While I agree with @cygri, it is often very desirable (e.g. in consulting situations) to have an easily readable RDFXML, and the Writer often spits out hard to digest RDF (probably due to streaming and optimization for memory consumption/speed).
I think you're going at this the wrong way.
Nesting is a concept that only makes sense when talking about trees. But RDF is not about trees, it's about triples. Forget for a while about the structure of the XML, and think about the triples that are encoded in the XML. I find
model.write(System.out, "N-TRIPLES");
most useful for that.You first need to understand what triples you want your RDF/XML file to express. As long as it expresses the right triples, it doesn't matter whether the one node is written nested inside the other or what order things appear in. These are purely “cosmetic” questions, like indentation.