Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing RDF/XML file from rdf Triples in rdflib

I have got rdf triples with me, now I am interested in generating RDF/XML file using rdflib in Python. Could you please give me some sample code to start.

Thanks

like image 794
Muhammad Imran Avatar asked May 30 '11 13:05

Muhammad Imran


2 Answers

The rdflib docs could be a good starting point, particularly the Getting Started section. For example:

import rdflib
from rdflib.Graph import Graph
g = Graph()
g.parse("http://www.w3.org/2000/10/rdf-tests/rdfcore/ntriples/test.nt", 
        format="nt")
g.serialize("test.rdf", format="rdf/xml")
like image 151
2 revs, 2 users 87% Avatar answered Oct 16 '22 04:10

2 revs, 2 users 87%


If rdf/xml format is unknown (depends on the version of rdflib), use instead:

g.serialize("test.rdf", format="pretty-xml")
like image 41
Ghis Avatar answered Oct 16 '22 03:10

Ghis