root/tests/rdfa2n3.c

Revision 1a1a08c790b7649a7f6c12fb9e40c0d3dbe70481, 2.0 KB (checked in by Manu Sporny <msporny@…>, 15 months ago)

Added DOCTYPE injection for documents without a DOCTYPE.
Also added support for the default graph/processor graph concept in
RDFa 1.1 Core.

  • Property mode set to 100644
Line 
1/*
2 * Copyright 2008 Digital Bazaar, Inc.
3 *
4 * This file is part of librdfa.
5 *
6 * librdfa is Free Software, and can be licensed under any of the
7 * following three licenses:
8 *
9 *   1. GNU Lesser General Public License (LGPL) V2.1 or any
10 *      newer version
11 *   2. GNU General Public License (GPL) V2 or any newer version
12 *   3. Apache License, V2.0 or any newer version
13 *
14 * You may not use this file except in compliance with at least one of
15 * the above three licenses.
16 *
17 * See LICENSE-* at the top of this software distribution for more
18 * information regarding the details of each license.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with librdfa. If not, see <http://www.gnu.org/licenses/>.
22 */
23#include <stdio.h>
24#include <string.h>
25#include <rdfa.h>
26#include <rdfa_utils.h>
27
28#define BASE_URI \
29   "http://rdfa.digitalbazaar.com/test-suite/tests-cases/"
30
31void process_triple(rdftriple* triple, void* callback_data)
32{
33   rdfa_print_triple(triple);
34   rdfa_free_triple(triple);
35}
36
37size_t fill_buffer(char* buffer, size_t buffer_length, void* callback_data)
38{
39   FILE* xhtml_file = (FILE*)callback_data;
40   size_t rval = fread(buffer, sizeof(char), buffer_length, xhtml_file);
41   return rval;
42}
43
44int main(int argc, char** argv)
45{
46   if(argc < 2)
47   {
48      printf("%s usage:\n\n"
49             "%s <input.xhtml>\n", argv[0], argv[0]);
50   }
51   else
52   {
53      FILE* xhtml_file = fopen(argv[1], "r");
54      char* filename = rindex(argv[1], '/');
55      filename++;
56
57      if(xhtml_file != NULL)
58      {
59         char* base_uri = rdfa_join_string(BASE_URI, filename);
60         rdfacontext* context = rdfa_create_context(base_uri);
61         context->callback_data = xhtml_file;
62
63         rdfa_set_default_graph_triple_handler(context, &process_triple);
64         rdfa_set_buffer_filler(context, &fill_buffer);
65         rdfa_parse(context);
66         rdfa_free_context(context);
67
68         fclose(xhtml_file);
69         free(base_uri);
70      }
71      else
72      {
73         perror("failed to open file:");
74      }
75   }
76
77   return 0;
78}
Note: See TracBrowser for help on using the browser.