Writing RDF / XML file from rdf Triples to rdflib

I have rdf triples with me, now I'm interested in generating an RDF / XML file using rdflib in Python. Could you give me some sample code to get you started.

thanks

+6
source share
2 answers

rdflib docs can be a good starting point, especially Getting Started . For instance:

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") 
+5
source

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

 g.serialize("test.rdf", format="pretty-xml") 
+3
source

Source: https://habr.com/ru/post/889382/


All Articles