From 4038ab95a094b363f1748f3dcb51511a1217475d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:40:05 +0200 Subject: Adding upstream version 2.0.16. Signed-off-by: Daniel Baumann --- examples/rdfserialize.c | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 examples/rdfserialize.c (limited to 'examples/rdfserialize.c') diff --git a/examples/rdfserialize.c b/examples/rdfserialize.c new file mode 100644 index 0000000..ecbc6b3 --- /dev/null +++ b/examples/rdfserialize.c @@ -0,0 +1,47 @@ +#include +#include +#include + +/* rdfserialize.c: serialize 1 triple to RDF/XML-Abbrev */ + +int +main(int argc, char *argv[]) +{ + raptor_world *world = NULL; + raptor_serializer* rdf_serializer = NULL; + unsigned char *uri_string; + raptor_uri *base_uri; + raptor_statement* triple; + + world = raptor_new_world(); + + uri_string = raptor_uri_filename_to_uri_string(argv[1]); + base_uri = raptor_new_uri(world, uri_string); + + rdf_serializer = raptor_new_serializer(world, "rdfxml-abbrev"); + raptor_serializer_start_to_file_handle(rdf_serializer, base_uri, stdout); + + /* Make a triple with URI subject, URI predicate, literal object */ + triple = raptor_new_statement(world); + triple->subject = raptor_new_term_from_uri_string(world, (const unsigned char*)"http://example.org/subject"); + triple->predicate = raptor_new_term_from_uri_string(world, (const unsigned char*)"http://example.org/predicate"); + triple->object = raptor_new_term_from_literal(world, + (const unsigned char*)"An example literal", + NULL, + (const unsigned char*)"en"); + + /* Write the triple */ + raptor_serializer_serialize_statement(rdf_serializer, triple); + + /* Delete the triple */ + raptor_free_statement(triple); + + raptor_serializer_serialize_end(rdf_serializer); + raptor_free_serializer(rdf_serializer); + + raptor_free_uri(base_uri); + raptor_free_memory(uri_string); + + raptor_free_world(world); + return 0; +} -- cgit v1.2.3