1 <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
4 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
5 <title>Simple XML Subset Parser</title>
6 <meta name="generator" content="DocBook XSL Stylesheets V1.75.2">
7 <link rel="home" href="index.html" title="GLib Reference Manual">
8 <link rel="up" href="glib-utilities.html" title="GLib Utilities">
9 <link rel="prev" href="glib-Perl-compatible-regular-expressions.html" title="Perl-compatible regular expressions">
10 <link rel="next" href="glib-Key-value-file-parser.html" title="Key-value file parser">
11 <meta name="generator" content="GTK-Doc V1.13 (XML mode)">
12 <link rel="stylesheet" href="style.css" type="text/css">
13 <link rel="chapter" href="glib.html" title="GLib Overview">
14 <link rel="chapter" href="glib-fundamentals.html" title="GLib Fundamentals">
15 <link rel="chapter" href="glib-core.html" title="GLib Core Application Support">
16 <link rel="chapter" href="glib-utilities.html" title="GLib Utilities">
17 <link rel="chapter" href="glib-data-types.html" title="GLib Data Types">
18 <link rel="chapter" href="tools.html" title="GLib Tools">
19 <link rel="index" href="api-index-full.html" title="Index">
20 <link rel="index" href="api-index-deprecated.html" title="Index of deprecated symbols">
21 <link rel="index" href="api-index-2-2.html" title="Index of new symbols in 2.2">
22 <link rel="index" href="api-index-2-4.html" title="Index of new symbols in 2.4">
23 <link rel="index" href="api-index-2-6.html" title="Index of new symbols in 2.6">
24 <link rel="index" href="api-index-2-8.html" title="Index of new symbols in 2.8">
25 <link rel="index" href="api-index-2-10.html" title="Index of new symbols in 2.10">
26 <link rel="index" href="api-index-2-12.html" title="Index of new symbols in 2.12">
27 <link rel="index" href="api-index-2-14.html" title="Index of new symbols in 2.14">
28 <link rel="index" href="api-index-2-16.html" title="Index of new symbols in 2.16">
29 <link rel="index" href="api-index-2-18.html" title="Index of new symbols in 2.18">
30 <link rel="index" href="api-index-2-20.html" title="Index of new symbols in 2.20">
31 <link rel="index" href="api-index-2-22.html" title="Index of new symbols in 2.22">
32 <link rel="index" href="api-index-2-24.html" title="Index of new symbols in 2.24">
34 <body bgcolor="white" text="black" link="#0000FF" vlink="#840084" alink="#0000FF">
35 <table class="navigation" id="top" width="100%" summary="Navigation header" cellpadding="2" cellspacing="2">
37 <td><a accesskey="p" href="glib-Perl-compatible-regular-expressions.html"><img src="left.png" width="24" height="24" border="0" alt="Prev"></a></td>
38 <td><a accesskey="u" href="glib-utilities.html"><img src="up.png" width="24" height="24" border="0" alt="Up"></a></td>
39 <td><a accesskey="h" href="index.html"><img src="home.png" width="24" height="24" border="0" alt="Home"></a></td>
40 <th width="100%" align="center">GLib Reference Manual</th>
41 <td><a accesskey="n" href="glib-Key-value-file-parser.html"><img src="right.png" width="24" height="24" border="0" alt="Next"></a></td>
43 <tr><td colspan="5" class="shortcuts">
44 <a href="#glib-Simple-XML-Subset-Parser.synopsis" class="shortcut">Top</a>
46 <a href="#glib-Simple-XML-Subset-Parser.description" class="shortcut">Description</a>
49 <div class="refentry" title="Simple XML Subset Parser">
50 <a name="glib-Simple-XML-Subset-Parser"></a><div class="titlepage"></div>
51 <div class="refnamediv"><table width="100%"><tr>
53 <h2><span class="refentrytitle"><a name="glib-Simple-XML-Subset-Parser.top_of_page"></a>Simple XML Subset Parser</span></h2>
54 <p>Simple XML Subset Parser — parses a subset of XML</p>
56 <td valign="top" align="right"></td>
58 <div class="refsynopsisdiv" title="Synopsis">
59 <a name="glib-Simple-XML-Subset-Parser.synopsis"></a><h2>Synopsis</h2>
60 <pre class="synopsis">
61 #include <glib.h>
63 enum <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupError" title="enum GMarkupError">GMarkupError</a>;
64 #define <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-ERROR:CAPS" title="G_MARKUP_ERROR">G_MARKUP_ERROR</a>
65 enum <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseFlags" title="enum GMarkupParseFlags">GMarkupParseFlags</a>;
66 <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext">GMarkupParseContext</a>;
67 <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser">GMarkupParser</a>;
68 <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a>* <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-escape-text" title="g_markup_escape_text ()">g_markup_escape_text</a> (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *text,
69 <a class="link" href="glib-Basic-Types.html#gssize" title="gssize"><span class="returnvalue">gssize</span></a> length);
70 <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-printf-escaped" title="g_markup_printf_escaped ()">g_markup_printf_escaped</a> (const <span class="returnvalue">char</span> *format,
72 <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-vprintf-escaped" title="g_markup_vprintf_escaped ()">g_markup_vprintf_escaped</a> (const <span class="returnvalue">char</span> *format,
73 <span class="returnvalue">va_list</span> args);
74 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-end-parse" title="g_markup_parse_context_end_parse ()">g_markup_parse_context_end_parse</a> (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context,
75 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error);
76 <span class="returnvalue">void</span> <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-free" title="g_markup_parse_context_free ()">g_markup_parse_context_free</a> (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context);
77 <span class="returnvalue">void</span> <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-get-position" title="g_markup_parse_context_get_position ()">g_markup_parse_context_get_position</a> (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context,
78 <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> *line_number,
79 <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> *char_number);
80 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-get-element" title="g_markup_parse_context_get_element ()">g_markup_parse_context_get_element</a> (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context);
81 const <a class="link" href="glib-Singly-Linked-Lists.html#GSList" title="GSList"><span class="returnvalue">GSList</span></a> * <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-get-element-stack" title="g_markup_parse_context_get_element_stack ()">g_markup_parse_context_get_element_stack</a>
82 (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context);
83 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-get-user-data" title="g_markup_parse_context_get_user_data ()">g_markup_parse_context_get_user_data</a>
84 (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context);
85 <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> * <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-new" title="g_markup_parse_context_new ()">g_markup_parse_context_new</a> (const <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="returnvalue">GMarkupParser</span></a> *parser,
86 <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseFlags" title="enum GMarkupParseFlags"><span class="returnvalue">GMarkupParseFlags</span></a> flags,
87 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> user_data,
88 <a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="returnvalue">GDestroyNotify</span></a> user_data_dnotify);
89 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-parse" title="g_markup_parse_context_parse ()">g_markup_parse_context_parse</a> (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context,
90 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *text,
91 <a class="link" href="glib-Basic-Types.html#gssize" title="gssize"><span class="returnvalue">gssize</span></a> text_len,
92 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error);
93 <span class="returnvalue">void</span> <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-push" title="g_markup_parse_context_push ()">g_markup_parse_context_push</a> (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context,
94 <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="returnvalue">GMarkupParser</span></a> *parser,
95 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> user_data);
96 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-pop" title="g_markup_parse_context_pop ()">g_markup_parse_context_pop</a> (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context);
98 enum <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupCollectType" title="enum GMarkupCollectType">GMarkupCollectType</a>;
99 <a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-collect-attributes" title="g_markup_collect_attributes ()">g_markup_collect_attributes</a> (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *element_name,
100 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> **attribute_names,
101 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> **attribute_values,
102 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error,
103 <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupCollectType" title="enum GMarkupCollectType"><span class="returnvalue">GMarkupCollectType</span></a> first_type,
104 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *first_attr,
108 <div class="refsect1" title="Description">
109 <a name="glib-Simple-XML-Subset-Parser.description"></a><h2>Description</h2>
111 The "GMarkup" parser is intended to parse a simple markup format
112 that's a subset of XML. This is a small, efficient, easy-to-use
113 parser. It should not be used if you expect to interoperate with other
114 applications generating full-scale XML. However, it's very useful for
115 application data files, config files, etc. where you know your
116 application will be the only one writing the file. Full-scale XML
117 parsers should be able to parse the subset used by GMarkup, so you can
118 easily migrate to full-scale XML at a later time if the need arises.
121 GMarkup is not guaranteed to signal an error on all invalid XML; the
122 parser may accept documents that an XML parser would not. However, XML
123 documents which are not well-formed<sup>[<a name="wellformed" href="#ftn.wellformed" class="footnote">5</a>]</sup> are not considered valid GMarkup
127 Simplifications to XML include:
129 <div class="itemizedlist"><ul class="itemizedlist" type="disc">
130 <li class="listitem"><p>
131 Only UTF-8 encoding is allowed.
133 <li class="listitem"><p>
134 No user-defined entities.
136 <li class="listitem"><p>
137 Processing instructions, comments and the doctype declaration are "passed
138 through" but are not interpreted in any way.
140 <li class="listitem"><p>
141 No DTD or validation.
147 The markup format does support:
149 <div class="itemizedlist"><ul class="itemizedlist" type="disc">
150 <li class="listitem"><p>
153 <li class="listitem"><p>
156 <li class="listitem"><p>
157 5 standard entities: <code class="literal">&amp; &lt; &gt; &quot; &apos;</code>
159 <li class="listitem"><p>
162 <li class="listitem"><p>
163 Sections marked as CDATA
169 <div class="refsect1" title="Details">
170 <a name="glib-Simple-XML-Subset-Parser.details"></a><h2>Details</h2>
171 <div class="refsect2" title="enum GMarkupError">
172 <a name="GMarkupError"></a><h3>enum GMarkupError</h3>
173 <pre class="programlisting">typedef enum
175 G_MARKUP_ERROR_BAD_UTF8,
176 G_MARKUP_ERROR_EMPTY,
177 G_MARKUP_ERROR_PARSE,
178 /* The following are primarily intended for specific GMarkupParser
179 * implementations to set.
181 G_MARKUP_ERROR_UNKNOWN_ELEMENT,
182 G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
183 G_MARKUP_ERROR_INVALID_CONTENT,
184 G_MARKUP_ERROR_MISSING_ATTRIBUTE
188 Error codes returned by markup parsing.
190 <div class="variablelist"><table border="0">
191 <col align="left" valign="top">
194 <td><p><a name="G-MARKUP-ERROR-BAD-UTF8:CAPS"></a><span class="term"><code class="literal">G_MARKUP_ERROR_BAD_UTF8</code></span></p></td>
195 <td>text being parsed was not valid UTF-8
199 <td><p><a name="G-MARKUP-ERROR-EMPTY:CAPS"></a><span class="term"><code class="literal">G_MARKUP_ERROR_EMPTY</code></span></p></td>
200 <td>document contained nothing, or only whitespace
204 <td><p><a name="G-MARKUP-ERROR-PARSE:CAPS"></a><span class="term"><code class="literal">G_MARKUP_ERROR_PARSE</code></span></p></td>
205 <td>document was ill-formed
209 <td><p><a name="G-MARKUP-ERROR-UNKNOWN-ELEMENT:CAPS"></a><span class="term"><code class="literal">G_MARKUP_ERROR_UNKNOWN_ELEMENT</code></span></p></td>
210 <td>error should be set by <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a> functions; element wasn't known
214 <td><p><a name="G-MARKUP-ERROR-UNKNOWN-ATTRIBUTE:CAPS"></a><span class="term"><code class="literal">G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE</code></span></p></td>
215 <td>error should be set by <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a> functions; attribute wasn't known
219 <td><p><a name="G-MARKUP-ERROR-INVALID-CONTENT:CAPS"></a><span class="term"><code class="literal">G_MARKUP_ERROR_INVALID_CONTENT</code></span></p></td>
220 <td>error should be set by <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a> functions; content was invalid
224 <td><p><a name="G-MARKUP-ERROR-MISSING-ATTRIBUTE:CAPS"></a><span class="term"><code class="literal">G_MARKUP_ERROR_MISSING_ATTRIBUTE</code></span></p></td>
225 <td>error should be set by <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a> functions; a required attribute was missing
232 <div class="refsect2" title="G_MARKUP_ERROR">
233 <a name="G-MARKUP-ERROR:CAPS"></a><h3>G_MARKUP_ERROR</h3>
234 <pre class="programlisting">#define G_MARKUP_ERROR g_markup_error_quark ()
237 Error domain for markup parsing. Errors in this domain will
238 be from the <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupError" title="enum GMarkupError"><span class="type">GMarkupError</span></a> enumeration. See <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> for information on
243 <div class="refsect2" title="enum GMarkupParseFlags">
244 <a name="GMarkupParseFlags"></a><h3>enum GMarkupParseFlags</h3>
245 <pre class="programlisting">typedef enum
247 G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
248 G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1,
249 G_MARKUP_PREFIX_ERROR_POSITION = 1 << 2
253 Flags that affect the behaviour of the parser.
255 <div class="variablelist"><table border="0">
256 <col align="left" valign="top">
259 <td><p><a name="G-MARKUP-DO-NOT-USE-THIS-UNSUPPORTED-FLAG:CAPS"></a><span class="term"><code class="literal">G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG</code></span></p></td>
260 <td>flag you should not use.
264 <td><p><a name="G-MARKUP-TREAT-CDATA-AS-TEXT:CAPS"></a><span class="term"><code class="literal">G_MARKUP_TREAT_CDATA_AS_TEXT</code></span></p></td>
265 <td>When this flag is set, CDATA marked
266 sections are not passed literally to the <em class="parameter"><code>passthrough</code></em> function of
267 the parser. Instead, the content of the section (without the
268 <code class="literal"><![CDATA[</code> and <code class="literal">]]></code>) is
269 passed to the <em class="parameter"><code>text</code></em> function. This flag was added in GLib 2.12.
273 <td><p><a name="G-MARKUP-PREFIX-ERROR-POSITION:CAPS"></a><span class="term"><code class="literal">G_MARKUP_PREFIX_ERROR_POSITION</code></span></p></td>
274 <td>Normally errors caught by GMarkup
275 itself have line/column information prefixed to them to let the
276 caller know the location of the error. When this flag is set the
277 location information is also prefixed to errors generated by the
278 <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a> implementation functions.
285 <div class="refsect2" title="GMarkupParseContext">
286 <a name="GMarkupParseContext"></a><h3>GMarkupParseContext</h3>
287 <pre class="programlisting">typedef struct _GMarkupParseContext GMarkupParseContext;</pre>
289 A parse context is used to parse a stream of bytes that you expect to
290 contain marked-up text. See <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-new" title="g_markup_parse_context_new ()"><code class="function">g_markup_parse_context_new()</code></a>,
291 <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a>, and so on for more details.
295 <div class="refsect2" title="GMarkupParser">
296 <a name="GMarkupParser"></a><h3>GMarkupParser</h3>
297 <pre class="programlisting">typedef struct {
298 /* Called for open tags <foo bar="baz"> */
299 void (*start_element) (GMarkupParseContext *context,
300 const gchar *element_name,
301 const gchar **attribute_names,
302 const gchar **attribute_values,
306 /* Called for close tags </foo> */
307 void (*end_element) (GMarkupParseContext *context,
308 const gchar *element_name,
312 /* Called for character data */
313 /* text is not nul-terminated */
314 void (*text) (GMarkupParseContext *context,
320 /* Called for strings that should be re-saved verbatim in this same
321 * position, but are not otherwise interpretable. At the moment
322 * this includes comments and processing instructions.
324 /* text is not nul-terminated. */
325 void (*passthrough) (GMarkupParseContext *context,
326 const gchar *passthrough_text,
331 /* Called on error, including one set by other
332 * methods in the vtable. The GError should not be freed.
334 void (*error) (GMarkupParseContext *context,
340 Any of the fields in <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a> can be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>, in which case they
341 will be ignored. Except for the <em class="parameter"><code>error</code></em> function, any of these
342 callbacks can set an error; in particular the
343 <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-ERROR-UNKNOWN-ELEMENT:CAPS"><code class="literal">G_MARKUP_ERROR_UNKNOWN_ELEMENT</code></a>, <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-ERROR-UNKNOWN-ATTRIBUTE:CAPS"><code class="literal">G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE</code></a>,
344 and <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-ERROR-INVALID-CONTENT:CAPS"><code class="literal">G_MARKUP_ERROR_INVALID_CONTENT</code></a> errors are intended to be set
345 from these callbacks. If you set an error from a callback,
346 <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-parse" title="g_markup_parse_context_parse ()"><code class="function">g_markup_parse_context_parse()</code></a> will report that error back to its caller.
348 <div class="variablelist"><table border="0">
349 <col align="left" valign="top">
352 <td><p><span class="term"><em class="structfield"><code><a name="GMarkupParser.start-element"></a>start_element</code></em> ()</span></p></td>
353 <td>Callback to invoke when the opening tag of an element
358 <td><p><span class="term"><em class="structfield"><code><a name="GMarkupParser.end-element"></a>end_element</code></em> ()</span></p></td>
359 <td>Callback to invoke when the closing tag of an element is seen.
360 Note that this is also called for empty tags like
361 <code class="literal"><empty/></code>.
365 <td><p><span class="term"><em class="structfield"><code><a name="GMarkupParser.text"></a>text</code></em> ()</span></p></td>
366 <td>Callback to invoke when some text is seen (text is always
367 inside an element). Note that the text of an element may be spread
368 over multiple calls of this function. If the <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-TREAT-CDATA-AS-TEXT:CAPS"><code class="literal">G_MARKUP_TREAT_CDATA_AS_TEXT</code></a>
369 flag is set, this function is also called for the content of CDATA marked
374 <td><p><span class="term"><em class="structfield"><code><a name="GMarkupParser.passthrough"></a>passthrough</code></em> ()</span></p></td>
375 <td>Callback to invoke for comments, processing instructions
376 and doctype declarations; if you're re-writing the parsed document,
377 write the passthrough text back out in the same position. If the
378 <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-TREAT-CDATA-AS-TEXT:CAPS"><code class="literal">G_MARKUP_TREAT_CDATA_AS_TEXT</code></a> flag is not set, this function is also
379 called for CDATA marked sections.
383 <td><p><span class="term"><em class="structfield"><code><a name="GMarkupParser.error"></a>error</code></em> ()</span></p></td>
384 <td>Callback to invoke when an error occurs.
391 <div class="refsect2" title="g_markup_escape_text ()">
392 <a name="g-markup-escape-text"></a><h3>g_markup_escape_text ()</h3>
393 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a>* g_markup_escape_text (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *text,
394 <a class="link" href="glib-Basic-Types.html#gssize" title="gssize"><span class="returnvalue">gssize</span></a> length);</pre>
396 Escapes text so that the markup parser will parse it verbatim.
397 Less than, greater than, ampersand, etc. are replaced with the
398 corresponding entities. This function would typically be used
399 when writing out a file to be parsed with the markup parser.
402 Note that this function doesn't protect whitespace and line endings
403 from being processed according to the XML rules for normalization
404 of line endings and attribute values.
407 Note also that if given a string containing them, this function
408 will produce character references in the range of &<span class="type">x1</span>; ..
409 &<span class="type">x1f</span>; for all control sequences except for tabstop, newline
410 and carriage return. The character references in this range are
411 not valid XML 1.0, but they are valid XML 1.1 and will be accepted
412 by the GMarkup parser.</p>
413 <div class="variablelist"><table border="0">
414 <col align="left" valign="top">
417 <td><p><span class="term"><em class="parameter"><code>text</code></em> :</span></p></td>
418 <td> some valid UTF-8 text
422 <td><p><span class="term"><em class="parameter"><code>length</code></em> :</span></p></td>
423 <td> length of <em class="parameter"><code>text</code></em> in bytes, or -1 if the text is nul-terminated
427 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
428 <td> a newly allocated string with the escaped text
435 <div class="refsect2" title="g_markup_printf_escaped ()">
436 <a name="g-markup-printf-escaped"></a><h3>g_markup_printf_escaped ()</h3>
437 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_markup_printf_escaped (const <span class="returnvalue">char</span> *format,
440 Formats arguments according to <em class="parameter"><code>format</code></em>, escaping
441 all string and character arguments in the fashion
442 of <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-escape-text" title="g_markup_escape_text ()"><code class="function">g_markup_escape_text()</code></a>. This is useful when you
443 want to insert literal strings into XML-style markup
444 output, without having to worry that the strings
445 might themselves contain markup.
449 <div class="informalexample"><pre class="programlisting">
450 const char *store = "Fortnum & Mason";
451 const char *item = "Tea";
454 output = g_markup_printf_escaped ("<purchase>"
455 "<store>%s</store>"
456 "<item>%s</item>"
460 <div class="variablelist"><table border="0">
461 <col align="left" valign="top">
464 <td><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td>
465 <td> <code class="function">printf()</code> style format string
469 <td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td>
470 <td> the arguments to insert in the format string
474 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
475 <td> newly allocated result from formatting
476 operation. Free with <a class="link" href="glib-Memory-Allocation.html#g-free" title="g_free ()"><code class="function">g_free()</code></a>.
482 <p class="since">Since 2.4</p>
485 <div class="refsect2" title="g_markup_vprintf_escaped ()">
486 <a name="g-markup-vprintf-escaped"></a><h3>g_markup_vprintf_escaped ()</h3>
487 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_markup_vprintf_escaped (const <span class="returnvalue">char</span> *format,
488 <span class="returnvalue">va_list</span> args);</pre>
490 Formats the data in <em class="parameter"><code>args</code></em> according to <em class="parameter"><code>format</code></em>, escaping
491 all string and character arguments in the fashion
492 of <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-escape-text" title="g_markup_escape_text ()"><code class="function">g_markup_escape_text()</code></a>. See <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-printf-escaped" title="g_markup_printf_escaped ()"><code class="function">g_markup_printf_escaped()</code></a>.</p>
493 <div class="variablelist"><table border="0">
494 <col align="left" valign="top">
497 <td><p><span class="term"><em class="parameter"><code>format</code></em> :</span></p></td>
498 <td> <code class="function">printf()</code> style format string
502 <td><p><span class="term"><em class="parameter"><code>args</code></em> :</span></p></td>
503 <td> variable argument list, similar to <code class="function">vprintf()</code>
507 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
508 <td> newly allocated result from formatting
509 operation. Free with <a class="link" href="glib-Memory-Allocation.html#g-free" title="g_free ()"><code class="function">g_free()</code></a>.
515 <p class="since">Since 2.4</p>
518 <div class="refsect2" title="g_markup_parse_context_end_parse ()">
519 <a name="g-markup-parse-context-end-parse"></a><h3>g_markup_parse_context_end_parse ()</h3>
520 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> g_markup_parse_context_end_parse (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context,
521 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error);</pre>
523 Signals to the <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a> that all data has been
524 fed into the parse context with <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-parse" title="g_markup_parse_context_parse ()"><code class="function">g_markup_parse_context_parse()</code></a>.
525 This function reports an error if the document isn't complete,
526 for example if elements are still open.</p>
527 <div class="variablelist"><table border="0">
528 <col align="left" valign="top">
531 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
532 <td> a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>
536 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
537 <td> return location for a <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>
541 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
542 <td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> on success, <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> if an error was set
549 <div class="refsect2" title="g_markup_parse_context_free ()">
550 <a name="g-markup-parse-context-free"></a><h3>g_markup_parse_context_free ()</h3>
551 <pre class="programlisting"><span class="returnvalue">void</span> g_markup_parse_context_free (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context);</pre>
553 Frees a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>. Can't be called from inside
554 one of the <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a> functions. Can't be called while
555 a subparser is pushed.</p>
556 <div class="variablelist"><table border="0">
557 <col align="left" valign="top">
559 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
560 <td> a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>
566 <div class="refsect2" title="g_markup_parse_context_get_position ()">
567 <a name="g-markup-parse-context-get-position"></a><h3>g_markup_parse_context_get_position ()</h3>
568 <pre class="programlisting"><span class="returnvalue">void</span> g_markup_parse_context_get_position (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context,
569 <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> *line_number,
570 <a class="link" href="glib-Basic-Types.html#gint" title="gint"><span class="returnvalue">gint</span></a> *char_number);</pre>
572 Retrieves the current line number and the number of the character on
573 that line. Intended for use in error messages; there are no strict
574 semantics for what constitutes the "current" line number other than
575 "the best number we could come up with for error messages."</p>
576 <div class="variablelist"><table border="0">
577 <col align="left" valign="top">
580 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
581 <td> a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>
585 <td><p><span class="term"><em class="parameter"><code>line_number</code></em> :</span></p></td>
586 <td> return location for a line number, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
590 <td><p><span class="term"><em class="parameter"><code>char_number</code></em> :</span></p></td>
591 <td> return location for a char-on-line number, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
598 <div class="refsect2" title="g_markup_parse_context_get_element ()">
599 <a name="g-markup-parse-context-get-element"></a><h3>g_markup_parse_context_get_element ()</h3>
600 <pre class="programlisting">const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> * g_markup_parse_context_get_element (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context);</pre>
602 Retrieves the name of the currently open element.
605 If called from the start_element or end_element handlers this will
606 give the element_name as passed to those functions. For the parent
607 elements, see <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-get-element-stack" title="g_markup_parse_context_get_element_stack ()"><code class="function">g_markup_parse_context_get_element_stack()</code></a>.</p>
608 <div class="variablelist"><table border="0">
609 <col align="left" valign="top">
612 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
613 <td> a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>
617 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
618 <td> the name of the currently open element, or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
623 <p class="since">Since 2.2</p>
626 <div class="refsect2" title="g_markup_parse_context_get_element_stack ()">
627 <a name="g-markup-parse-context-get-element-stack"></a><h3>g_markup_parse_context_get_element_stack ()</h3>
628 <pre class="programlisting">const <a class="link" href="glib-Singly-Linked-Lists.html#GSList" title="GSList"><span class="returnvalue">GSList</span></a> * g_markup_parse_context_get_element_stack
629 (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context);</pre>
631 Retrieves the element stack from the internal state of the parser.
632 The returned <a class="link" href="glib-Singly-Linked-Lists.html#GSList" title="GSList"><span class="type">GSList</span></a> is a list of strings where the first item is
633 the currently open tag (as would be returned by
634 <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-get-element" title="g_markup_parse_context_get_element ()"><code class="function">g_markup_parse_context_get_element()</code></a>) and the next item is its
638 This function is intended to be used in the start_element and
639 end_element handlers where <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-get-element" title="g_markup_parse_context_get_element ()"><code class="function">g_markup_parse_context_get_element()</code></a>
640 would merely return the name of the element that is being
642 <div class="variablelist"><table border="0">
643 <col align="left" valign="top">
646 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
647 <td> a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>
651 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
652 <td> the element stack, which must not be modified
658 <p class="since">Since 2.16</p>
661 <div class="refsect2" title="g_markup_parse_context_get_user_data ()">
662 <a name="g-markup-parse-context-get-user-data"></a><h3>g_markup_parse_context_get_user_data ()</h3>
663 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> g_markup_parse_context_get_user_data
664 (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context);</pre>
666 Returns the user_data associated with <em class="parameter"><code>context</code></em>. This will either
667 be the user_data that was provided to <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-new" title="g_markup_parse_context_new ()"><code class="function">g_markup_parse_context_new()</code></a>
668 or to the most recent call of <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-push" title="g_markup_parse_context_push ()"><code class="function">g_markup_parse_context_push()</code></a>.</p>
669 <div class="variablelist"><table border="0">
670 <col align="left" valign="top">
673 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
674 <td> a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>
678 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
679 <td> the provided user_data. The returned data belongs to
680 the markup context and will be freed when <code class="function">g_markup_context_free()</code>
687 <p class="since">Since 2.18</p>
690 <div class="refsect2" title="g_markup_parse_context_new ()">
691 <a name="g-markup-parse-context-new"></a><h3>g_markup_parse_context_new ()</h3>
692 <pre class="programlisting"><a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> * g_markup_parse_context_new (const <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="returnvalue">GMarkupParser</span></a> *parser,
693 <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseFlags" title="enum GMarkupParseFlags"><span class="returnvalue">GMarkupParseFlags</span></a> flags,
694 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> user_data,
695 <a class="link" href="glib-Datasets.html#GDestroyNotify" title="GDestroyNotify ()"><span class="returnvalue">GDestroyNotify</span></a> user_data_dnotify);</pre>
697 Creates a new parse context. A parse context is used to parse
698 marked-up documents. You can feed any number of documents into
699 a context, as long as no errors occur; once an error occurs,
700 the parse context can't continue to parse text (you have to free it
701 and create a new parse context).</p>
702 <div class="variablelist"><table border="0">
703 <col align="left" valign="top">
706 <td><p><span class="term"><em class="parameter"><code>parser</code></em> :</span></p></td>
707 <td> a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a>
711 <td><p><span class="term"><em class="parameter"><code>flags</code></em> :</span></p></td>
712 <td> one or more <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseFlags" title="enum GMarkupParseFlags"><span class="type">GMarkupParseFlags</span></a>
716 <td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
717 <td> user data to pass to <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a> functions
721 <td><p><span class="term"><em class="parameter"><code>user_data_dnotify</code></em> :</span></p></td>
722 <td> user data destroy notifier called when the parse context is freed
726 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
727 <td> a new <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>
734 <div class="refsect2" title="g_markup_parse_context_parse ()">
735 <a name="g-markup-parse-context-parse"></a><h3>g_markup_parse_context_parse ()</h3>
736 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> g_markup_parse_context_parse (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context,
737 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *text,
738 <a class="link" href="glib-Basic-Types.html#gssize" title="gssize"><span class="returnvalue">gssize</span></a> text_len,
739 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error);</pre>
741 Feed some data to the <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>. The data need not
742 be valid UTF-8; an error will be signaled if it's invalid.
743 The data need not be an entire document; you can feed a document
744 into the parser incrementally, via multiple calls to this function.
745 Typically, as you receive data from a network connection or file,
746 you feed each received chunk of data into this function, aborting
747 the process if an error occurs. Once an error is reported, no further
748 data may be fed to the <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>; all errors are fatal.</p>
749 <div class="variablelist"><table border="0">
750 <col align="left" valign="top">
753 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
754 <td> a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>
758 <td><p><span class="term"><em class="parameter"><code>text</code></em> :</span></p></td>
759 <td> chunk of text to parse
763 <td><p><span class="term"><em class="parameter"><code>text_len</code></em> :</span></p></td>
764 <td> length of <em class="parameter"><code>text</code></em> in bytes
768 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
769 <td> return location for a <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a>
773 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
774 <td> <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> if an error occurred, <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> on success
781 <div class="refsect2" title="g_markup_parse_context_push ()">
782 <a name="g-markup-parse-context-push"></a><h3>g_markup_parse_context_push ()</h3>
783 <pre class="programlisting"><span class="returnvalue">void</span> g_markup_parse_context_push (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context,
784 <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="returnvalue">GMarkupParser</span></a> *parser,
785 <a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> user_data);</pre>
787 Temporarily redirects markup data to a sub-parser.
790 This function may only be called from the start_element handler of
791 a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a>. It must be matched with a corresponding call to
792 <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-pop" title="g_markup_parse_context_pop ()"><code class="function">g_markup_parse_context_pop()</code></a> in the matching end_element handler
793 (except in the case that the parser aborts due to an error).
796 All tags, text and other data between the matching tags is
797 redirected to the subparser given by <em class="parameter"><code>parser</code></em>. <em class="parameter"><code>user_data</code></em> is used
798 as the user_data for that parser. <em class="parameter"><code>user_data</code></em> is also passed to the
799 error callback in the event that an error occurs. This includes
800 errors that occur in subparsers of the subparser.
803 The end tag matching the start tag for which this call was made is
804 handled by the previous parser (which is given its own user_data)
805 which is why <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-pop" title="g_markup_parse_context_pop ()"><code class="function">g_markup_parse_context_pop()</code></a> is provided to allow "one
806 last access" to the <em class="parameter"><code>user_data</code></em> provided to this function. In the
807 case of error, the <em class="parameter"><code>user_data</code></em> provided here is passed directly to
808 the error callback of the subparser and <code class="function">g_markup_parse_context()</code>
809 should not be called. In either case, if <em class="parameter"><code>user_data</code></em> was allocated
810 then it ought to be freed from both of these locations.
813 This function is not intended to be directly called by users
814 interested in invoking subparsers. Instead, it is intended to be
815 used by the subparsers themselves to implement a higher-level
819 As an example, see the following implementation of a simple
820 parser that counts the number of tags encountered.
824 <div class="informalexample"><pre class="programlisting">
831 counter_start_element (GMarkupParseContext *context,
832 const gchar *element_name,
833 const gchar **attribute_names,
834 const gchar **attribute_values,
838 CounterData *data = user_data;
840 data->tag_count++;
844 counter_error (GMarkupParseContext *context,
848 CounterData *data = user_data;
850 g_slice_free (CounterData, data);
853 static GMarkupParser counter_subparser =
855 counter_start_element,
865 In order to allow this parser to be easily used as a subparser, the
866 following interface is provided:
870 <div class="informalexample"><pre class="programlisting">
872 start_counting (GMarkupParseContext *context)
874 CounterData *data = g_slice_new (CounterData);
876 data->tag_count = 0;
877 g_markup_parse_context_push (context, &counter_subparser, data);
881 end_counting (GMarkupParseContext *context)
883 CounterData *data = g_markup_parse_context_pop (context);
886 result = data->tag_count;
887 g_slice_free (CounterData, data);
895 The subparser would then be used as follows:
899 <div class="informalexample"><pre class="programlisting">
900 static void start_element (context, element_name, ...)
902 if (strcmp (element_name, "count-these") == 0)
903 start_counting (context);
905 /* else, handle other tags... */
908 static void end_element (context, element_name, ...)
910 if (strcmp (element_name, "count-these") == 0)
911 g_print ("Counted %d tags\n", end_counting (context));
913 /* else, handle other tags... */
916 <div class="variablelist"><table border="0">
917 <col align="left" valign="top">
920 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
921 <td> a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>
925 <td><p><span class="term"><em class="parameter"><code>parser</code></em> :</span></p></td>
926 <td> a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a>
930 <td><p><span class="term"><em class="parameter"><code>user_data</code></em> :</span></p></td>
931 <td> user data to pass to <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a> functions
936 <p class="since">Since 2.18</p>
939 <div class="refsect2" title="g_markup_parse_context_pop ()">
940 <a name="g-markup-parse-context-pop"></a><h3>g_markup_parse_context_pop ()</h3>
941 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gpointer" title="gpointer"><span class="returnvalue">gpointer</span></a> g_markup_parse_context_pop (<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="returnvalue">GMarkupParseContext</span></a> *context);</pre>
943 Completes the process of a temporary sub-parser redirection.
946 This function exists to collect the user_data allocated by a
947 matching call to <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-push" title="g_markup_parse_context_push ()"><code class="function">g_markup_parse_context_push()</code></a>. It must be called
948 in the end_element handler corresponding to the start_element
949 handler during which <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-push" title="g_markup_parse_context_push ()"><code class="function">g_markup_parse_context_push()</code></a> was called. You
950 must not call this function from the error callback -- the
951 <em class="parameter"><code>user_data</code></em> is provided directly to the callback in that case.
954 This function is not intended to be directly called by users
955 interested in invoking subparsers. Instead, it is intended to be
956 used by the subparsers themselves to implement a higher-level
958 <div class="variablelist"><table border="0">
959 <col align="left" valign="top">
962 <td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td>
963 <td> a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext" title="GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>
967 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
968 <td> the user_data passed to <a class="link" href="glib-Simple-XML-Subset-Parser.html#g-markup-parse-context-push" title="g_markup_parse_context_push ()"><code class="function">g_markup_parse_context_push()</code></a>.
974 <p class="since">Since 2.18</p>
977 <div class="refsect2" title="enum GMarkupCollectType">
978 <a name="GMarkupCollectType"></a><h3>enum GMarkupCollectType</h3>
979 <pre class="programlisting">typedef enum
981 G_MARKUP_COLLECT_INVALID,
982 G_MARKUP_COLLECT_STRING,
983 G_MARKUP_COLLECT_STRDUP,
984 G_MARKUP_COLLECT_BOOLEAN,
985 G_MARKUP_COLLECT_TRISTATE,
987 G_MARKUP_COLLECT_OPTIONAL = (1 << 16)
988 } GMarkupCollectType;
991 A mixed enumerated type and flags field. You must specify one type
992 (string, strdup, boolean, tristate). Additionally, you may
993 optionally bitwise OR the type with the flag
994 <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-COLLECT-OPTIONAL:CAPS"><code class="literal">G_MARKUP_COLLECT_OPTIONAL</code></a>.
997 It is likely that this enum will be extended in the future to
998 support other types.</p>
999 <div class="variablelist"><table border="0">
1000 <col align="left" valign="top">
1003 <td><p><a name="G-MARKUP-COLLECT-INVALID:CAPS"></a><span class="term"><code class="literal">G_MARKUP_COLLECT_INVALID</code></span></p></td>
1004 <td> used to terminate the list of attributes
1009 <td><p><a name="G-MARKUP-COLLECT-STRING:CAPS"></a><span class="term"><code class="literal">G_MARKUP_COLLECT_STRING</code></span></p></td>
1010 <td> collect the string pointer directly from
1011 the attribute_values[] array. Expects a
1012 parameter of type (const char **). If
1013 <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-COLLECT-OPTIONAL:CAPS"><code class="literal">G_MARKUP_COLLECT_OPTIONAL</code></a> is specified
1014 and the attribute isn't present then the
1015 pointer will be set to <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>.
1019 <td><p><a name="G-MARKUP-COLLECT-STRDUP:CAPS"></a><span class="term"><code class="literal">G_MARKUP_COLLECT_STRDUP</code></span></p></td>
1020 <td> as with <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-COLLECT-STRING:CAPS"><code class="literal">G_MARKUP_COLLECT_STRING</code></a>, but
1021 expects a parameter of type (char **) and
1022 <a class="link" href="glib-String-Utility-Functions.html#g-strdup" title="g_strdup ()"><code class="function">g_strdup()</code></a>s the returned pointer. The
1023 pointer must be freed with <a class="link" href="glib-Memory-Allocation.html#g-free" title="g_free ()"><code class="function">g_free()</code></a>.
1027 <td><p><a name="G-MARKUP-COLLECT-BOOLEAN:CAPS"></a><span class="term"><code class="literal">G_MARKUP_COLLECT_BOOLEAN</code></span></p></td>
1028 <td> expects a parameter of type (gboolean *)
1029 and parses the attribute value as a
1030 boolean. Sets <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> if the attribute
1031 isn't present. Valid boolean values
1032 consist of (case insensitive) "false",
1033 "f", "no", "n", "0" and "true", "t",
1038 <td><p><a name="G-MARKUP-COLLECT-TRISTATE:CAPS"></a><span class="term"><code class="literal">G_MARKUP_COLLECT_TRISTATE</code></span></p></td>
1039 <td> as with <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-COLLECT-BOOLEAN:CAPS"><code class="literal">G_MARKUP_COLLECT_BOOLEAN</code></a>, but
1040 in the case of a missing attribute a
1041 value is set that compares equal to
1042 neither <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a> nor <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a>.
1043 G_MARKUP_COLLECT_OPTIONAL is implied.
1047 <td><p><a name="G-MARKUP-COLLECT-OPTIONAL:CAPS"></a><span class="term"><code class="literal">G_MARKUP_COLLECT_OPTIONAL</code></span></p></td>
1048 <td> can be bitwise ORed with the other
1049 fields. If present, allows the
1050 attribute not to appear. A default
1051 value is set depending on what value
1059 <div class="refsect2" title="g_markup_collect_attributes ()">
1060 <a name="g-markup-collect-attributes"></a><h3>g_markup_collect_attributes ()</h3>
1061 <pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean" title="gboolean"><span class="returnvalue">gboolean</span></a> g_markup_collect_attributes (const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *element_name,
1062 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> **attribute_names,
1063 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> **attribute_values,
1064 <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="returnvalue">GError</span></a> **error,
1065 <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupCollectType" title="enum GMarkupCollectType"><span class="returnvalue">GMarkupCollectType</span></a> first_type,
1066 const <a class="link" href="glib-Basic-Types.html#gchar" title="gchar"><span class="returnvalue">gchar</span></a> *first_attr,
1069 Collects the attributes of the element from the
1070 data passed to the <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser" title="GMarkupParser"><span class="type">GMarkupParser</span></a> start_element
1071 function, dealing with common error conditions
1072 and supporting boolean values.
1075 This utility function is not required to write
1076 a parser but can save a lot of typing.
1079 The <em class="parameter"><code>element_name</code></em>, <em class="parameter"><code>attribute_names</code></em>,
1080 <em class="parameter"><code>attribute_values</code></em> and <em class="parameter"><code>error</code></em> parameters passed
1081 to the start_element callback should be passed
1082 unmodified to this function.
1085 Following these arguments is a list of
1086 "supported" attributes to collect. It is an
1087 error to specify multiple attributes with the
1088 same name. If any attribute not in the list
1089 appears in the <em class="parameter"><code>attribute_names</code></em> array then an
1090 unknown attribute error will result.
1093 The <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupCollectType" title="enum GMarkupCollectType"><span class="type">GMarkupCollectType</span></a> field allows specifying
1094 the type of collection to perform and if a
1095 given attribute must appear or is optional.
1098 The attribute name is simply the name of the
1099 attribute to collect.
1102 The pointer should be of the appropriate type
1103 (see the descriptions under
1104 <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupCollectType" title="enum GMarkupCollectType"><span class="type">GMarkupCollectType</span></a>) and may be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a> in case a
1105 particular attribute is to be allowed but
1109 This function deals with issuing errors for missing attributes
1110 (of type <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-ERROR-MISSING-ATTRIBUTE:CAPS"><code class="literal">G_MARKUP_ERROR_MISSING_ATTRIBUTE</code></a>), unknown attributes
1111 (of type <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-ERROR-UNKNOWN-ATTRIBUTE:CAPS"><code class="literal">G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE</code></a>) and duplicate
1112 attributes (of type <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-ERROR-INVALID-CONTENT:CAPS"><code class="literal">G_MARKUP_ERROR_INVALID_CONTENT</code></a>) as well
1113 as parse errors for boolean-valued attributes (again of type
1114 <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-ERROR-INVALID-CONTENT:CAPS"><code class="literal">G_MARKUP_ERROR_INVALID_CONTENT</code></a>). In all of these cases <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS" title="FALSE"><code class="literal">FALSE</code></a>
1115 will be returned and <em class="parameter"><code>error</code></em> will be set as appropriate.</p>
1116 <div class="variablelist"><table border="0">
1117 <col align="left" valign="top">
1120 <td><p><span class="term"><em class="parameter"><code>element_name</code></em> :</span></p></td>
1121 <td> the current tag name
1125 <td><p><span class="term"><em class="parameter"><code>attribute_names</code></em> :</span></p></td>
1126 <td> the attribute names
1130 <td><p><span class="term"><em class="parameter"><code>attribute_values</code></em> :</span></p></td>
1131 <td> the attribute values
1135 <td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td>
1136 <td> a pointer to a <a class="link" href="glib-Error-Reporting.html#GError" title="GError"><span class="type">GError</span></a> or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>
1140 <td><p><span class="term"><em class="parameter"><code>first_type</code></em> :</span></p></td>
1141 <td> the <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupCollectType" title="enum GMarkupCollectType"><span class="type">GMarkupCollectType</span></a> of the
1146 <td><p><span class="term"><em class="parameter"><code>first_attr</code></em> :</span></p></td>
1147 <td> the name of the first attribute
1151 <td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td>
1152 <td> a pointer to the storage location of the
1153 first attribute (or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS" title="NULL"><code class="literal">NULL</code></a>), followed by
1154 more types names and pointers, ending
1155 with <a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-COLLECT-INVALID:CAPS"><code class="literal">G_MARKUP_COLLECT_INVALID</code></a>.
1159 <td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td>
1160 <td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS" title="TRUE"><code class="literal">TRUE</code></a> if successful
1166 <p class="since">Since 2.16</p>
1169 <div class="footnotes">
1170 <br><hr width="100" align="left">
1171 <div class="footnote"><a class="ulink" href="http://www.w3.org/TR/REC-xml/" target="_top"><sup>[<a name="ftn.wellformed" href="#wellformed" class="ulink">5</a>] </sup>XML specification</a></div>
1174 <div class="footer">
1176 Generated by GTK-Doc V1.13</div>