summaryrefslogtreecommitdiffstats
path: root/docs/rdfcat.c
blob: 978a641a2bd1f94f15884639c91db794c1dafa34 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
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;
}