These serializers are available in default RDFLib, you can use them by passing the name to graph's :meth:`~rdflib.graph.Graph.parse` method:
graph.parse(my_url, format='n3')
The html
parser will auto-detect RDFa, HTurtle or Microdata.
It is also possible to pass a mime-type for the format
parameter:
graph.parse(my_url, format='application/rdf+xml')
If you are not sure what format your file will be, you can use :func:`rdflib.util.guess_format` which will guess based on the file extension.
Note that for correct parsing of multi-graph data, e.g. Trig, HexT, etc., into a Dataset
,
as opposed to a context-unaware Graph
, you will need to set the publicID
of the Dataset
to the identifier of the default_context
(default graph), for example:
d = Dataset() d.parse( data=""" ... """, format="trig", publicID=d.default_context.identifier )
(from the file tests/test_serializer_hext.py)