1 /* gmarkup.h - Simple XML-like string parser/writer
3 * Copyright 2000 Red Hat, Inc.
5 * GLib is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU Lesser General Public License as
7 * published by the Free Software Foundation; either version 2 of the
8 * License, or (at your option) any later version.
10 * GLib is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Lesser General Public License for more details.
15 * You should have received a copy of the GNU Lesser General Public
16 * License along with GLib; see the file COPYING.LIB. If not,
17 * write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 * Boston, MA 02111-1307, USA.
21 #ifndef __G_MARKUP_H__
22 #define __G_MARKUP_H__
26 #include <glib/gerror.h>
27 #include <glib/gslist.h>
33 G_MARKUP_ERROR_BAD_UTF8,
36 /* The following are primarily intended for specific GMarkupParser
37 * implementations to set.
39 G_MARKUP_ERROR_UNKNOWN_ELEMENT,
40 G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
41 G_MARKUP_ERROR_INVALID_CONTENT,
42 G_MARKUP_ERROR_MISSING_ATTRIBUTE
45 #define G_MARKUP_ERROR g_markup_error_quark ()
47 GQuark g_markup_error_quark (void);
51 G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
52 G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1,
53 G_MARKUP_PREFIX_ERROR_POSITION = 1 << 2
56 typedef struct _GMarkupParseContext GMarkupParseContext;
57 typedef struct _GMarkupParser GMarkupParser;
61 /* Called for open tags <foo bar="baz"> */
62 void (*start_element) (GMarkupParseContext *context,
63 const gchar *element_name,
64 const gchar **attribute_names,
65 const gchar **attribute_values,
69 /* Called for close tags </foo> */
70 void (*end_element) (GMarkupParseContext *context,
71 const gchar *element_name,
75 /* Called for character data */
76 /* text is not nul-terminated */
77 void (*text) (GMarkupParseContext *context,
83 /* Called for strings that should be re-saved verbatim in this same
84 * position, but are not otherwise interpretable. At the moment
85 * this includes comments and processing instructions.
87 /* text is not nul-terminated. */
88 void (*passthrough) (GMarkupParseContext *context,
89 const gchar *passthrough_text,
94 /* Called on error, including one set by other
95 * methods in the vtable. The GError should not be freed.
97 void (*error) (GMarkupParseContext *context,
102 GMarkupParseContext *g_markup_parse_context_new (const GMarkupParser *parser,
103 GMarkupParseFlags flags,
105 GDestroyNotify user_data_dnotify);
106 void g_markup_parse_context_free (GMarkupParseContext *context);
107 gboolean g_markup_parse_context_parse (GMarkupParseContext *context,
112 gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context,
114 G_CONST_RETURN gchar *g_markup_parse_context_get_element (GMarkupParseContext *context);
115 G_CONST_RETURN GSList *g_markup_parse_context_get_element_stack (GMarkupParseContext *context);
117 /* For user-constructed error messages, has no precise semantics */
118 void g_markup_parse_context_get_position (GMarkupParseContext *context,
122 /* useful when saving */
123 gchar* g_markup_escape_text (const gchar *text,
126 gchar *g_markup_printf_escaped (const char *format,
127 ...) G_GNUC_PRINTF (1, 2);
128 gchar *g_markup_vprintf_escaped (const char *format,
133 G_MARKUP_COLLECT_INVALID,
134 G_MARKUP_COLLECT_STRING,
135 G_MARKUP_COLLECT_STRDUP,
136 G_MARKUP_COLLECT_BOOLEAN,
137 G_MARKUP_COLLECT_TRISTATE,
139 G_MARKUP_COLLECT_OPTIONAL = (1 << 16)
140 } GMarkupCollectType;
143 /* useful from start_element */
144 gboolean g_markup_collect_attributes (const gchar *element_name,
145 const gchar **attribute_names,
146 const gchar **attribute_values,
148 GMarkupCollectType first_type,
149 const gchar *first_attr,
154 #endif /* __G_MARKUP_H__ */