Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert RDF to string

Tags:

java

rdf

jena

I create some RDF file wih JENA library: Model model = ModelFactory.createDefaultModel();... now how I can I convert this to string ?

thx

like image 604
hudi Avatar asked Dec 10 '22 01:12

hudi


1 Answers

Try something like this:

String syntax = "RDF/XML-ABBREV"; // also try "N-TRIPLE" and "TURTLE"
StringWriter out = new StringWriter();
model.write(out, syntax);
String result = out.toString();

This uses Jena's built-in writers that can already output RDF graphs in the various supported RDF syntaxes, such as RDF/XML and Turtle and N-Triples. If you just want to dump to System.out, then it's even easier:

model.write(System.out, "RDF/XML-ABBREV");
like image 61
cygri Avatar answered Jan 03 '23 16:01

cygri