How to get nested RDF/XML from Jena?

我怕爱的太早我们不能终老 提交于 2019-12-05 12:25:49

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.

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).

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!