diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:40:05 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-15 05:40:05 +0000 |
commit | 4038ab95a094b363f1748f3dcb51511a1217475d (patch) | |
tree | 7f393d66a783f91ddd263c78d681e485cf4f45ca /examples/rdfcat.c | |
parent | Initial commit. (diff) | |
download | raptor2-8a74621eb7909f43a549b042a496e042ad12fdcb.tar.xz raptor2-8a74621eb7909f43a549b042a496e042ad12fdcb.zip |
Adding upstream version 2.0.16.upstream/2.0.16upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | examples/rdfcat.c | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/examples/rdfcat.c b/examples/rdfcat.c new file mode 100644 index 0000000..978a641 --- /dev/null +++ b/examples/rdfcat.c @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <raptor2.h> + +/* rdfcat.c: parse any RDF syntax and serialize to RDF/XML-Abbrev */ + +static raptor_serializer* rdf_serializer; + +static void +serialize_triple(void* user_data, raptor_statement* triple) +{ + raptor_serializer_serialize_statement(rdf_serializer, triple); +} + +static void +declare_namespace(void* user_data, raptor_namespace *nspace) +{ + raptor_serializer_set_namespace_from_namespace(rdf_serializer, nspace); +} + +int +main(int argc, char *argv[]) +{ + raptor_world *world = NULL; + raptor_parser* rdf_parser = NULL; + unsigned char *uri_string; + raptor_uri *uri, *base_uri; + + world = raptor_new_world(); + + uri_string = raptor_uri_filename_to_uri_string(argv[1]); + uri = raptor_new_uri(world, uri_string); + base_uri = raptor_uri_copy(uri); + + /* Ask raptor to work out which parser to use */ + rdf_parser = raptor_new_parser(world, "guess"); + raptor_parser_set_statement_handler(rdf_parser, NULL, serialize_triple); + raptor_parser_set_namespace_handler(rdf_parser, NULL, declare_namespace); + + rdf_serializer = raptor_new_serializer(world, "rdfxml-abbrev"); + + raptor_serializer_start_to_file_handle(rdf_serializer, base_uri, stdout); + raptor_parser_parse_file(rdf_parser, uri, base_uri); + raptor_serializer_serialize_end(rdf_serializer); + + raptor_free_serializer(rdf_serializer); + raptor_free_parser(rdf_parser); + + raptor_free_uri(base_uri); + raptor_free_uri(uri); + raptor_free_memory(uri_string); + + raptor_free_world(world); + + return 0; +} |