7

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

Muhammad Imran
  • 991
  • 1
  • 8
  • 6

2 Answers2

7

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")
Landric
  • 263
  • 1
  • 6
  • 21
Jukka Matilainen
  • 7,585
  • 1
  • 22
  • 17
4

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

g.serialize("test.rdf", format="pretty-xml")
Ghis
  • 670
  • 7
  • 13