diff options
author | Dave Beckett <dave@dajobe.org> | 2006-04-20 07:14:26 +0000 |
---|---|---|
committer | Dave Beckett <dave@dajobe.org> | 2006-04-20 07:14:26 +0000 |
commit | 92954b356712b2ca608626133cf47aa1cb30fe95 (patch) | |
tree | 8ff7a6bba7b5879abf80ad746124a8a3b597164e /examples | |
parent | 6d939209d09ab3f44c53641755bd7db5f8c1c752 (diff) | |
download | raptor-92954b356712b2ca608626133cf47aa1cb30fe95.tar.gz |
Add tutorial examples rdfcat.c rdfprint.c
Diffstat (limited to 'examples')
-rw-r--r-- | examples/rdfcat.c | 52 | ||||
-rw-r--r-- | examples/rdfprint.c | 39 |
2 files changed, 91 insertions, 0 deletions
diff --git a/examples/rdfcat.c b/examples/rdfcat.c new file mode 100644 index 00000000..ab2ab3e7 --- /dev/null +++ b/examples/rdfcat.c @@ -0,0 +1,52 @@ +#include <stdio.h> +#include <raptor.h> + +/* rdfcat.c: parse any RDF syntax and serialize to RDF/XML-Abbrev */ + +static raptor_serializer* rdf_serializer; + +void +serialize_triple(void* user_data, const raptor_statement* triple) +{ + raptor_serialize_statement(rdf_serializer, triple); +} + +static void +declare_namespace(void* user_data, raptor_namespace *nspace) +{ + raptor_serialize_set_namespace_from_namespace(rdf_serializer, nspace); +} + +int +main(int argc, char *argv[]) +{ + raptor_parser* rdf_parser=NULL; + unsigned char *uri_string; + raptor_uri *uri, *base_uri; + + raptor_init(); + + uri_string=raptor_uri_filename_to_uri_string(argv[1]); + uri=raptor_new_uri(uri_string); + base_uri=raptor_uri_copy(uri); + + /* Ask raptor to work out which parser to use */ + rdf_parser=raptor_new_parser("guess"); + raptor_set_statement_handler(rdf_parser, NULL, serialize_triple); + raptor_set_namespace_handler(rdf_parser, NULL, declare_namespace); + + rdf_serializer=raptor_new_serializer("rdfxml-abbrev"); + + raptor_serialize_start_to_file_handle(rdf_serializer, base_uri, stdout); + raptor_parse_file(rdf_parser, uri, base_uri); + raptor_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_finish(); +} diff --git a/examples/rdfprint.c b/examples/rdfprint.c new file mode 100644 index 00000000..23c394b6 --- /dev/null +++ b/examples/rdfprint.c @@ -0,0 +1,39 @@ +#include <stdio.h> +#include <raptor.h> + +/* rdfprint.c: print triples from parsing RDF/XML */ + +void +print_triple(void* user_data, const raptor_statement* triple) +{ + raptor_print_statement_as_ntriples(triple, stdout); + fputc('\n', stdout); +} + +int +main(int argc, char *argv[]) +{ + raptor_parser* rdf_parser=NULL; + unsigned char *uri_string; + raptor_uri *uri, *base_uri; + + raptor_init(); + + rdf_parser=raptor_new_parser("rdfxml"); + + raptor_set_statement_handler(rdf_parser, NULL, print_triple); + + uri_string=raptor_uri_filename_to_uri_string(argv[1]); + uri=raptor_new_uri(uri_string); + base_uri=raptor_uri_copy(uri); + + raptor_parse_file(rdf_parser, uri, base_uri); + + raptor_free_parser(rdf_parser); + + raptor_free_uri(base_uri); + raptor_free_uri(uri); + raptor_free_memory(uri_string); + + raptor_finish(); +} |