javardfjenaxml-namespacesn-triples

How to Convert rdf xml into n-triples?


I an RDF document in RDF/XML file that I want to convert into N-Triples. How can I convert it using Jena?

<rdf:RDF xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
         xmlns:dc="http://purl.org/dc/elements/1.1/">
  <rdf:Description rdf:about="http://www.w3.org/2001/sw/RDFCore/ntriples/">
    <dc:creator>Art Barstow</dc:creator>
    <dc:creator>Dave Beckett</dc:creator>
    <dc:publisher rdf:resource="http://www.w3.org/"/>
  </rdf:Description>
</rdf:RDF>

Solution

  • Read the file using "RDF/XML" mode and convert it using write function in "N-TURTLE" mode..

    ie,

    m.read(new FileInputStream (new File("yourfile")),"RDF/XML");
    
    m.write(new FileOutputStream (new File("yourfile")) , "N-TRIPLE");
    

    That's it.