1 /* -*- Mode: c; c-basic-offset: 2 -*-
2 *
3 * raptor_expat.c - Raptor expat functions
4 *
5 * Copyright (C) 2000-2006, David Beckett http://www.dajobe.org/
6 * Copyright (C) 2000-2004, University of Bristol, UK http://www.bristol.ac.uk/
7 *
8 * This package is Free Software and part of Redland http://librdf.org/
9 *
10 * It is licensed under the following three licenses as alternatives:
11 * 1. GNU Lesser General Public License (LGPL) V2.1 or any newer version
12 * 2. GNU General Public License (GPL) V2 or any newer version
13 * 3. Apache License, V2.0 or any newer version
14 *
15 * You may not use this file except in compliance with at least one of
16 * the above three licenses.
17 *
18 * See LICENSE.html or LICENSE.txt at the top of this package for the
19 * complete terms and further detail along with the license texts for
20 * the licenses in COPYING.LIB, COPYING and LICENSE-2.0.txt respectively.
21 *
22 *
23 */
24
25
26 #ifdef HAVE_CONFIG_H
27 #include <raptor_config.h>
28 #endif
29
30 #ifdef WIN32
31 #include <win32_raptor_config.h>
32 #endif
33
34 #include <stdio.h>
35 #include <string.h>
36 #include <ctype.h>
37 #include <stdarg.h>
38 #ifdef HAVE_ERRNO_H
39 #include <errno.h>
40 #endif
41 #ifdef HAVE_STDLIB_H
42 #include <stdlib.h>
43 #endif
44
45 /* Raptor includes */
46 #include "raptor.h"
47 #include "raptor_internal.h"
48
49
50 #ifdef RAPTOR_XML_EXPAT
51
52
53 void
raptor_expat_init(raptor_sax2 * sax2,raptor_uri * base_uri)54 raptor_expat_init(raptor_sax2* sax2, raptor_uri *base_uri)
55 {
56 XML_Parser xp=XML_ParserCreate(NULL);
57
58 /* create a new parser in the specified encoding */
59 XML_SetUserData(xp, sax2);
60
61 XML_SetBase(xp, (XML_Char*)raptor_uri_as_string_v2(sax2->world, base_uri));
62
63 /* XML_SetEncoding(xp, "..."); */
64
65 XML_SetElementHandler(xp,
66 (XML_StartElementHandler)raptor_sax2_start_element,
67 (XML_EndElementHandler)raptor_sax2_end_element);
68 XML_SetCharacterDataHandler(xp,
69 (XML_CharacterDataHandler)raptor_sax2_characters);
70
71 XML_SetCommentHandler(xp, (XML_CommentHandler)raptor_sax2_comment);
72
73 XML_SetUnparsedEntityDeclHandler(xp,
74 (XML_UnparsedEntityDeclHandler)raptor_sax2_unparsed_entity_decl);
75
76 XML_SetExternalEntityRefHandler(xp, (XML_ExternalEntityRefHandler)raptor_sax2_external_entity_ref);
77
78 sax2->xp=xp;
79 }
80
81
82 void
raptor_expat_update_document_locator(raptor_sax2 * sax2,raptor_locator * locator)83 raptor_expat_update_document_locator(raptor_sax2* sax2,
84 raptor_locator* locator)
85 {
86 locator->line=XML_GetCurrentLineNumber(sax2->xp);
87 locator->column=XML_GetCurrentColumnNumber(sax2->xp);
88 locator->byte=XML_GetCurrentByteIndex(sax2->xp);
89 }
90
91 /* end if RAPTOR_XML_EXPAT */
92 #endif
93