Benben
Benben

Reputation: 1455

Jena RDF API write method

I'm using Apache Jena API to read a rdf file and write it out to the console. This is the Java code.

Model model = ModelFactory.createDefaultModel();
InputStream in = FileManager.get().open("file.rdf");
model.read(in, null);
model.write(System.out);

This is the RDF file.

<rdf:RDF
  xmlns:rdf='http://www.w3.org/1999/02/22-rdf-syntax-ns#'
  xmlns:vcard='http://www.w3.org/2001/vcard-rdf/3.0#'
 >
  <rdf:Description rdf:nodeID="A0">
    <vcard:Family>Smith</vcard:Family>
    <vcard:Given>John</vcard:Given>
  </rdf:Description>
  <rdf:Description rdf:about='http://somewhere/JohnSmith/'>
    <vcard:FN>John Smith</vcard:FN>
    <vcard:N rdf:nodeID="A0"/>
  </rdf:Description>
  <rdf:Description rdf:about='http://somewhere/SarahJones/'>
    <vcard:FN>Sarah Jones</vcard:FN>
    <vcard:N rdf:nodeID="A1"/>
  </rdf:Description>
  <rdf:Description rdf:about='http://somewhere/MattJones/'>
    <vcard:FN>Matt Jones</vcard:FN>
    <vcard:N rdf:nodeID="A2"/>
  </rdf:Description>
  <rdf:Description rdf:nodeID="A3">
    <vcard:Family>Smith</vcard:Family>
    <vcard:Given>Rebecca</vcard:Given>
  </rdf:Description>
</rdf:RDF>

This is the output.

<rdf:RDF
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" > 
</rdf:RDF>

The problem is that my program does not write out the whole RDF data. How can I write out the whole RDF data?

Upvotes: 0

Views: 442

Answers (1)

Onasus
Onasus

Reputation: 240

I have pretty much the same application and it worked. I cannot tell you what is wrong with your code but at least this is how I did it:

Model myModel = FileManager.get().loadModel("file.rdf");

then I was able to read again with:

myModel.write (System.out, "RDF/XML");

I hope it helps!

Upvotes: 1

Related Questions