2
* "$Id: mxml.h 22267 2006-04-24 17:11:45Z kpfleming $"
4
* Header file for Mini-XML, a small XML-like file parsing library.
6
* Copyright 2003-2005 by Michael Sweet.
8
* This program is free software; you can redistribute it and/or
9
* modify it under the terms of the GNU Library General Public
10
* License as published by the Free Software Foundation; either
11
* version 2, or (at your option) any later version.
13
* This program is distributed in the hope that it will be useful,
14
* but WITHOUT ANY WARRANTY; without even the implied warranty of
15
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
* GNU General Public License for more details.
20
* Prevent multiple inclusion...
27
* Include necessary headers...
41
# define MXML_WRAP 72 /* Wrap XML output at this column position */
42
# define MXML_TAB 8 /* Tabs every N columns */
44
# define MXML_NO_CALLBACK 0 /* Don't use a type callback */
45
# define MXML_INTEGER_CALLBACK mxml_integer_cb
46
/* Treat all data as integers */
47
# define MXML_OPAQUE_CALLBACK mxml_opaque_cb
48
/* Treat all data as opaque */
49
# define MXML_REAL_CALLBACK mxml_real_cb
50
/* Treat all data as real numbers */
51
# define MXML_TEXT_CALLBACK 0 /* Treat all data as text */
53
# define MXML_NO_PARENT 0 /* No parent for the node */
55
# define MXML_DESCEND 1 /* Descend when finding/walking */
56
# define MXML_NO_DESCEND 0 /* Don't descend when finding/walking */
57
# define MXML_DESCEND_FIRST -1 /* Descend for first find */
59
# define MXML_WS_BEFORE_OPEN 0 /* Callback for before open tag */
60
# define MXML_WS_AFTER_OPEN 1 /* Callback for after open tag */
61
# define MXML_WS_BEFORE_CLOSE 2 /* Callback for before close tag */
62
# define MXML_WS_AFTER_CLOSE 3 /* Callback for after close tag */
64
# define MXML_ADD_BEFORE 0 /* Add node before specified node */
65
# define MXML_ADD_AFTER 1 /* Add node after specified node */
66
# define MXML_ADD_TO_PARENT NULL /* Add node relative to parent */
73
typedef enum mxml_type_e /**** The XML node type. ****/
75
MXML_ELEMENT, /* XML element with attributes */
76
MXML_INTEGER, /* Integer value */
77
MXML_OPAQUE, /* Opaque string */
78
MXML_REAL, /* Real value */
79
MXML_TEXT, /* Text fragment */
80
MXML_CUSTOM /* Custom data */
83
typedef struct mxml_attr_s /**** An XML element attribute value. ****/
85
char *name; /* Attribute name */
86
char *value; /* Attribute value */
89
typedef struct mxml_value_s /**** An XML element value. ****/
91
char *name; /* Name of element */
92
int num_attrs; /* Number of attributes */
93
mxml_attr_t *attrs; /* Attributes */
96
typedef struct mxml_text_s /**** An XML text value. ****/
98
int whitespace; /* Leading whitespace? */
99
char *string; /* Fragment string */
102
typedef struct mxml_custom_s /**** An XML custom value. ****/
104
void *data; /* Pointer to (allocated) custom data */
105
void (*destroy)(void *);
106
/* Pointer to destructor function */
109
typedef union mxml_value_u /**** An XML node value. ****/
111
mxml_element_t element; /* Element */
112
int integer; /* Integer number */
113
char *opaque; /* Opaque string */
114
double real; /* Real number */
115
mxml_text_t text; /* Text fragment */
116
mxml_custom_t custom; /* Custom data */
119
typedef struct mxml_node_s /**** An XML node. ****/
121
mxml_type_t type; /* Node type */
122
struct mxml_node_s *next; /* Next node under same parent */
123
struct mxml_node_s *prev; /* Previous node under same parent */
124
struct mxml_node_s *parent; /* Parent node */
125
struct mxml_node_s *child; /* First child node */
126
struct mxml_node_s *last_child; /* Last child node */
127
mxml_value_t value; /* Node value */
130
typedef struct mxml_index_s /**** An XML node index. ****/
132
char *attr; /* Attribute used for indexing or NULL */
133
int num_nodes; /* Number of nodes in index */
134
int alloc_nodes; /* Allocated nodes in index */
135
int cur_node; /* Current node */
136
mxml_node_t **nodes; /* Node array */
139
typedef int (*mxml_custom_load_cb_t)(mxml_node_t *, const char *);
140
/**** Custom data load callback function ****/
142
typedef char *(*mxml_custom_save_cb_t)(mxml_node_t *);
143
/**** Custom data save callback function ****/
152
# endif /* __cplusplus */
158
extern void mxmlAdd(mxml_node_t *parent, int where,
159
mxml_node_t *child, mxml_node_t *node);
160
extern void mxmlDelete(mxml_node_t *node);
161
extern const char *mxmlElementGetAttr(mxml_node_t *node, const char *name);
162
extern void mxmlElementSetAttr(mxml_node_t *node, const char *name,
164
extern int mxmlEntityAddCallback(int (*cb)(const char *name));
165
extern const char *mxmlEntityGetName(int val);
166
extern int mxmlEntityGetValue(const char *name);
167
extern void mxmlEntityRemoveCallback(int (*cb)(const char *name));
168
extern mxml_node_t *mxmlFindElement(mxml_node_t *node, mxml_node_t *top,
169
const char *name, const char *attr,
170
const char *value, int descend);
171
extern void mxmlIndexDelete(mxml_index_t *ind);
172
extern mxml_node_t *mxmlIndexEnum(mxml_index_t *ind);
173
extern mxml_node_t *mxmlIndexFind(mxml_index_t *ind,
176
extern mxml_index_t *mxmlIndexNew(mxml_node_t *node, const char *element,
178
extern mxml_node_t *mxmlIndexReset(mxml_index_t *ind);
179
extern mxml_node_t *mxmlLoadFd(mxml_node_t *top, int fd,
180
mxml_type_t (*cb)(mxml_node_t *));
181
extern mxml_node_t *mxmlLoadFile(mxml_node_t *top, FILE *fp,
182
mxml_type_t (*cb)(mxml_node_t *));
183
extern mxml_node_t *mxmlLoadString(mxml_node_t *top, const char *s,
184
mxml_type_t (*cb)(mxml_node_t *));
185
extern mxml_node_t *mxmlNewCustom(mxml_node_t *parent, void *data,
186
void (*destroy)(void *));
187
extern mxml_node_t *mxmlNewElement(mxml_node_t *parent, const char *name);
188
extern mxml_node_t *mxmlNewInteger(mxml_node_t *parent, int integer);
189
extern mxml_node_t *mxmlNewOpaque(mxml_node_t *parent, const char *opaque);
190
extern mxml_node_t *mxmlNewReal(mxml_node_t *parent, double real);
191
extern mxml_node_t *mxmlNewText(mxml_node_t *parent, int whitespace,
193
extern mxml_node_t *mxmlNewTextf(mxml_node_t *parent, int whitespace,
194
const char *format, ...)
196
__attribute__ ((__format__ (__printf__, 3, 4)))
197
# endif /* __GNUC__ */
199
extern void mxmlRemove(mxml_node_t *node);
200
extern char *mxmlSaveAllocString(mxml_node_t *node,
201
const char *(*cb)(mxml_node_t *, int));
202
extern int mxmlSaveFd(mxml_node_t *node, int fd,
203
const char *(*cb)(mxml_node_t *, int));
204
extern int mxmlSaveFile(mxml_node_t *node, FILE *fp,
205
const char *(*cb)(mxml_node_t *, int));
206
extern int mxmlSaveString(mxml_node_t *node, char *buffer,
208
const char *(*cb)(mxml_node_t *, int));
209
extern int mxmlSetCustom(mxml_node_t *node, void *data,
210
void (*destroy)(void *));
211
extern void mxmlSetCustomHandlers(mxml_custom_load_cb_t load,
212
mxml_custom_save_cb_t save);
213
extern int mxmlSetElement(mxml_node_t *node, const char *name);
214
extern void mxmlSetErrorCallback(void (*cb)(const char *));
215
extern int mxmlSetInteger(mxml_node_t *node, int integer);
216
extern int mxmlSetOpaque(mxml_node_t *node, const char *opaque);
217
extern int mxmlSetReal(mxml_node_t *node, double real);
218
extern int mxmlSetText(mxml_node_t *node, int whitespace,
220
extern int mxmlSetTextf(mxml_node_t *node, int whitespace,
221
const char *format, ...)
223
__attribute__ ((__format__ (__printf__, 3, 4)))
224
# endif /* __GNUC__ */
226
extern mxml_node_t *mxmlWalkNext(mxml_node_t *node, mxml_node_t *top,
228
extern mxml_node_t *mxmlWalkPrev(mxml_node_t *node, mxml_node_t *top,
233
* Private functions...
236
extern void mxml_error(const char *format, ...);
237
extern mxml_type_t mxml_integer_cb(mxml_node_t *node);
238
extern mxml_type_t mxml_opaque_cb(mxml_node_t *node);
239
extern mxml_type_t mxml_real_cb(mxml_node_t *node);
248
# endif /* __cplusplus */
249
#endif /* !_mxml_h_ */
253
* End of "$Id: mxml.h 22267 2006-04-24 17:11:45Z kpfleming $".