source: branches/1.3/src/core/scew/parser.h @ 5675

Last change on this file since 5675 was 5675, checked in by ldelgass, 9 years ago

merge r5673 from trunk (eol-style)

  • Property svn:eol-style set to native
File size: 5.2 KB
Line 
1/**
2 *
3 * @file     parser.h
4 * @author   Aleix Conchillo Flaque <aleix@member.fsf.org>
5 * @date     Mon Nov 25, 2002 00:57
6 * @brief    SCEW parser type declaration
7 *
8 * $Id: parser.h,v 1.2 2004/05/25 20:23:05 aleix Exp $
9 *
10 * @if copyright
11 *
12 * Copyright (C) 2002, 2003, 2004 Aleix Conchillo Flaque
13 *
14 * SCEW is free software; you can redistribute it and/or
15 * modify it under the terms of the GNU Lesser General Public
16 * License as published by the Free Software Foundation; either
17 * version 2.1 of the License, or (at your option) any later version.
18 *
19 * SCEW is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
22 * Lesser General Public License for more details.
23 *
24 * You should have received a copy of the GNU Lesser General Public
25 * License along with this library; if not, write to the Free Software
26 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
27 *
28 * @endif
29 *
30 * These are the parser functions that allow to read an XML tree from a
31 * file or a memory buffer.
32 */
33
34
35#ifndef PARSER_H_ALEIX0211250057
36#define PARSER_H_ALEIX0211250057
37
38#include "types.h"
39
40#include <expat.h>
41
42#include <stdio.h>
43
44#ifdef __cplusplus
45extern "C" {
46#endif /* __cplusplus */
47
48/**
49 * Creates a new parser. The parser is needed to load XML documents.
50 */
51extern scew_parser*
52scew_parser_create();
53
54/**
55 * Frees a parser memory structure. This function will <b>not</b> free
56 * the <code>scew_tree</code> generated by the parser, so it is
57 * important that you keep a pointer to it and remember to free it.
58 *
59 * @see scew_tree_free
60 */
61extern void
62scew_parser_free(scew_parser* parser);
63
64/**
65 * Loads an XML tree from the specified file name using the given
66 * parser.
67 *
68 * @param parser the SCEW parser.
69 * @param file_name the file to load the XML from.
70 *
71 * @see scew_parser_create
72 *
73 * @return 1 if file was successfully loaded, 0 otherwise.
74 */
75extern unsigned int
76scew_parser_load_file(scew_parser* parser, char const* file_name);
77
78/**
79 * Loads an XML tree from the specified file pointer using the
80 * given parser.
81 *
82 * @param parser the SCEW parser.
83 * @param in the file pointer to load the XML from.
84 *
85 * @see scew_parser_create
86 *
87 * @return 1 if file was successfully loaded, 0 otherwise.
88 */
89extern unsigned int
90scew_parser_load_file_fp(scew_parser* parser, FILE* in);
91
92/**
93 * Loads an XML tree from the specified memory buffer of the specified
94 * size using the given parser.
95 *
96 * @param parser the SCEW parser.
97 * @param buffer memory buffer to load XML from.
98 * @param size size in bytes of the memory buffer.
99 *
100 * @see scew_parser_create
101 *
102 * @return 1 if buffer was successfully loaded, 0 otherwise.
103 */
104extern unsigned int
105scew_parser_load_buffer(scew_parser* parser, char const* buffer,
106                        unsigned int size);
107
108/**
109 * Loads an XML tree from the specified stream buffer. Will call the
110 * callback (set using scew_parser_set_stream_callback) at the end of
111 * each message.
112 *
113 * @param parser the SCEW parser.
114 * @param buffer memory buffer to load XML from.
115 * @param size size in bytes of the memory buffer.
116 *
117 * @see scew_parser_create
118 * @see scew_parser_set_stream_callback
119 *
120 * @return 1 if buffer was successfully loaded, 0 otherwise.
121 */
122extern unsigned int
123scew_parser_load_stream(scew_parser* parser, char const* buffer,
124                        unsigned int size);
125
126/**
127 * Sets the callback for use when reading streams.
128 *
129 * @param parser the SCEW parser
130 * @param cb the callback function
131 */
132void
133scew_parser_set_stream_callback(scew_parser* parser, SCEW_CALLBACK* cb);
134
135/**
136 * Returns the XML tree read by the parser. Remember that
137 * <code>scew_parser_free</code> does not free the
138 * <code>scew_tree</code> read.
139 *
140 * @see tree.h
141 */
142extern scew_tree*
143scew_parser_tree(scew_parser const* parser);
144
145/**
146 * Returns the internal Expat parser. Probably some low-level Expat
147 * functions need to be called. This function gives you access to the
148 * Expat parser so you will be able to call those functions. If you
149 * modify the Expat parser event handling routines, SCEW will not be
150 * able to load the XML tree.
151 */
152extern XML_Parser
153scew_parser_expat(scew_parser* parser);
154
155/**
156 * Tells the parser how to treat white spaces. The default is to ignore
157 * heading and trailing white spaces.
158 *
159 * There is a new section in XML specification which talks about how to
160 * handle white spaces in XML. One can set an optional attribtue to an
161 * element, this attribute is called 'xml:space', and it can be set to
162 * 'default' or 'preserve', and it inherits its value from parent
163 * elements. 'preserve' means to leave white spaces as their are found,
164 * and 'default' means that white spaces are handled by the XML
165 * processor (Expat in our case) the way it wants to.
166 *
167 * This function gives the possibility to change the XML processor
168 * behaviour.
169 *
170 * @param parser the parser to set the option to.
171 * @param ignore 0 if you do <b>not</b> want to ignore white spaces, any
172 * other value otherwise.
173 */
174extern void
175scew_parser_ignore_whitespaces(scew_parser* parser, int ignore);
176
177#ifdef __cplusplus
178}
179#endif /* __cplusplus */
180
181#endif /* PARSER_H_ALEIX0211250057 */
Note: See TracBrowser for help on using the repository browser.