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 --- docs/html/tutorial-parser-example.html | 97 ++++++++++++++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 docs/html/tutorial-parser-example.html (limited to 'docs/html/tutorial-parser-example.html') diff --git a/docs/html/tutorial-parser-example.html b/docs/html/tutorial-parser-example.html new file mode 100644 index 0000000..9ef3fc4 --- /dev/null +++ b/docs/html/tutorial-parser-example.html @@ -0,0 +1,97 @@ + + + + +Parsing example code: Raptor RDF Syntax Library Manual + + + + + + + + + + + + + + + + +
+

+Parsing example code

+
+

Example 2. rdfprint.c: Parse an RDF/XML file and print the triples

+
+
+#include <stdio.h>
+#include <raptor2.h>
+
+/* rdfprint.c: print triples from parsing RDF/XML */
+
+static void
+print_triple(void* user_data, raptor_statement* triple) 
+{
+  raptor_statement_print_as_ntriples(triple, stdout);
+  fputc('\n', stdout);
+}
+
+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();
+
+  rdf_parser = raptor_new_parser(world, "rdfxml");
+
+  raptor_parser_set_statement_handler(rdf_parser, NULL, print_triple);
+
+  uri_string = raptor_uri_filename_to_uri_string(argv[1]);
+  uri = raptor_new_uri(world, uri_string);
+  base_uri = raptor_uri_copy(uri);
+
+  raptor_parser_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_free_world(world);
+
+  return 0;
+}
+
+
+

Compile it like this: +

+
+$ gcc -o rdfprint rdfprint.c `pkg-config raptor2 --cflags --libs`
+
+

+and run it on an RDF file as: +

+
+$ ./rdfprint raptor.rdf
+_:genid1 <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <http://usefulinc.com/ns/doap#Project> .
+_:genid1 <http://usefulinc.com/ns/doap#name> "Raptor" .
+_:genid1 <http://usefulinc.com/ns/doap#homepage> <http://librdf.org/raptor/> .
+...
+
+

+

+
+
+
+
+ + + \ No newline at end of file -- cgit v1.2.3