9
9
<refname>Simple XML Subset Parser</refname>
10
10
<refpurpose>parses a subset of XML</refpurpose>
11
<!--[<xref linkend="desc" endterm="desc.title"/>]-->
14
<refsynopsisdiv role="synopsis">
13
<refsynopsisdiv id="glib-Simple-XML-Subset-Parser.synopsis" role="synopsis">
15
14
<title role="synopsis.title">Synopsis</title>
19
18
#include <glib.h>
22
20
enum <link linkend="GMarkupError">GMarkupError</link>;
23
#define <link linkend="G-MARKUP-ERROR:CAPS">G_MARKUP_ERROR</link>
21
#define <link linkend="G-MARKUP-ERROR--CAPS">G_MARKUP_ERROR</link>
24
22
enum <link linkend="GMarkupParseFlags">GMarkupParseFlags</link>;
25
23
<link linkend="GMarkupParseContext">GMarkupParseContext</link>;
26
24
<link linkend="GMarkupParser">GMarkupParser</link>;
27
25
<link linkend="gchar">gchar</link>* <link linkend="g-markup-escape-text">g_markup_escape_text</link> (const <link linkend="gchar">gchar</link> *text,
28
26
<link linkend="gssize">gssize</link> length);
29
<link linkend="gchar">gchar</link>* <link linkend="g-markup-printf-escaped">g_markup_printf_escaped</link> (const <link linkend="char">char</link> *format,
27
<link linkend="gchar">gchar</link> * <link linkend="g-markup-printf-escaped">g_markup_printf_escaped</link> (const <link linkend="char">char</link> *format,
31
<link linkend="gchar">gchar</link>* <link linkend="g-markup-vprintf-escaped">g_markup_vprintf_escaped</link> (const <link linkend="char">char</link> *format,
29
<link linkend="gchar">gchar</link> * <link linkend="g-markup-vprintf-escaped">g_markup_vprintf_escaped</link> (const <link linkend="char">char</link> *format,
32
30
<link linkend="va-list">va_list</link> args);
33
31
<link linkend="gboolean">gboolean</link> <link linkend="g-markup-parse-context-end-parse">g_markup_parse_context_end_parse</link> (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context,
34
32
<link linkend="GError">GError</link> **error);
71
<refsect1 role="desc">
74
<refsect1 id="glib-Simple-XML-Subset-Parser.description" role="desc">
72
75
<title role="desc.title">Description</title>
74
77
The "GMarkup" parser is intended to parse a simple markup format
75
78
that's a subset of XML. This is a small, efficient, easy-to-use
76
parser. It should not be used if you expect to interoperate with other
79
parser. It should not be used if you expect to interoperate with other
77
80
applications generating full-scale XML. However, it's very useful for
78
81
application data files, config files, etc. where you know your
79
82
application will be the only one writing the file. Full-scale XML
80
83
parsers should be able to parse the subset used by GMarkup, so you can
81
84
easily migrate to full-scale XML at a later time if the need arises.
85
87
GMarkup is not guaranteed to signal an error on all invalid XML; the
86
parser may accept documents that an XML parser would not. However, XML
88
parser may accept documents that an XML parser would not. However, XML
87
89
documents which are not well-formed<footnote id="wellformed">Being wellformed
88
is a weaker condition than being valid. See the
89
<ulink url="http://www.w3.org/TR/REC-xml/">XML specification</ulink> for
90
definitions of these terms.</footnote> are not considered valid GMarkup
90
is a weaker condition than being valid. See the
91
<ulink url="http://www.w3.org/TR/REC-xml/">XML specification</ulink> for
92
definitions of these terms.</footnote> are not considered valid GMarkup
95
96
Simplifications to XML include:
172
172
Error codes returned by markup parsing.
173
173
</para><variablelist role="enum">
175
<term><anchor id="G-MARKUP-ERROR-BAD-UTF8:CAPS" role="constant"/><literal>G_MARKUP_ERROR_BAD_UTF8</literal></term>
174
<varlistentry id="G-MARKUP-ERROR-BAD-UTF8--CAPS" role="constant">
175
<term><literal>G_MARKUP_ERROR_BAD_UTF8</literal></term>
176
176
<listitem><simpara>text being parsed was not valid UTF-8
177
177
</simpara></listitem>
180
<term><anchor id="G-MARKUP-ERROR-EMPTY:CAPS" role="constant"/><literal>G_MARKUP_ERROR_EMPTY</literal></term>
179
<varlistentry id="G-MARKUP-ERROR-EMPTY--CAPS" role="constant">
180
<term><literal>G_MARKUP_ERROR_EMPTY</literal></term>
181
181
<listitem><simpara>document contained nothing, or only whitespace
182
182
</simpara></listitem>
185
<term><anchor id="G-MARKUP-ERROR-PARSE:CAPS" role="constant"/><literal>G_MARKUP_ERROR_PARSE</literal></term>
184
<varlistentry id="G-MARKUP-ERROR-PARSE--CAPS" role="constant">
185
<term><literal>G_MARKUP_ERROR_PARSE</literal></term>
186
186
<listitem><simpara>document was ill-formed
187
187
</simpara></listitem>
190
<term><anchor id="G-MARKUP-ERROR-UNKNOWN-ELEMENT:CAPS" role="constant"/><literal>G_MARKUP_ERROR_UNKNOWN_ELEMENT</literal></term>
189
<varlistentry id="G-MARKUP-ERROR-UNKNOWN-ELEMENT--CAPS" role="constant">
190
<term><literal>G_MARKUP_ERROR_UNKNOWN_ELEMENT</literal></term>
191
191
<listitem><simpara>error should be set by <link linkend="GMarkupParser"><type>GMarkupParser</type></link> functions; element wasn't known
192
192
</simpara></listitem>
195
<term><anchor id="G-MARKUP-ERROR-UNKNOWN-ATTRIBUTE:CAPS" role="constant"/><literal>G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE</literal></term>
194
<varlistentry id="G-MARKUP-ERROR-UNKNOWN-ATTRIBUTE--CAPS" role="constant">
195
<term><literal>G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE</literal></term>
196
196
<listitem><simpara>error should be set by <link linkend="GMarkupParser"><type>GMarkupParser</type></link> functions; attribute wasn't known
197
197
</simpara></listitem>
200
<term><anchor id="G-MARKUP-ERROR-INVALID-CONTENT:CAPS" role="constant"/><literal>G_MARKUP_ERROR_INVALID_CONTENT</literal></term>
199
<varlistentry id="G-MARKUP-ERROR-INVALID-CONTENT--CAPS" role="constant">
200
<term><literal>G_MARKUP_ERROR_INVALID_CONTENT</literal></term>
201
201
<listitem><simpara>error should be set by <link linkend="GMarkupParser"><type>GMarkupParser</type></link> functions; content was invalid
202
202
</simpara></listitem>
205
<term><anchor id="G-MARKUP-ERROR-MISSING-ATTRIBUTE:CAPS" role="constant"/><literal>G_MARKUP_ERROR_MISSING_ATTRIBUTE</literal></term>
204
<varlistentry id="G-MARKUP-ERROR-MISSING-ATTRIBUTE--CAPS" role="constant">
205
<term><literal>G_MARKUP_ERROR_MISSING_ATTRIBUTE</literal></term>
206
206
<listitem><simpara>error should be set by <link linkend="GMarkupParser"><type>GMarkupParser</type></link> functions; a required attribute was missing
208
207
</simpara></listitem>
210
209
</variablelist></refsect2>
212
<title><anchor id="G-MARKUP-ERROR:CAPS" role="macro"/>G_MARKUP_ERROR</title>
213
<indexterm><primary>G_MARKUP_ERROR</primary></indexterm><programlisting>#define G_MARKUP_ERROR g_markup_error_quark ()
210
<refsect2 id="G-MARKUP-ERROR--CAPS" role="macro">
211
<title>G_MARKUP_ERROR</title>
212
<indexterm zone="G-MARKUP-ERROR--CAPS"><primary sortas="G_MARKUP_ERROR">G_MARKUP_ERROR</primary></indexterm><programlisting>#define G_MARKUP_ERROR g_markup_error_quark ()
214
213
</programlisting>
216
215
Error domain for markup parsing. Errors in this domain will
217
be from the <link linkend="GMarkupError"><type>GMarkupError</type></link> enumeration. See <link linkend="GError"><type>GError</type></link> for information on
216
be from the <link linkend="GMarkupError"><type>GMarkupError</type></link> enumeration. See <link linkend="GError"><type>GError</type></link> for information on
219
218
</para></refsect2>
221
<title><anchor id="GMarkupParseFlags" role="enum"/>enum GMarkupParseFlags</title>
222
<indexterm><primary>GMarkupParseFlags</primary></indexterm><programlisting>typedef enum
219
<refsect2 id="GMarkupParseFlags" role="enum">
220
<title>enum GMarkupParseFlags</title>
221
<indexterm zone="GMarkupParseFlags"><primary sortas="GMarkupParseFlags">GMarkupParseFlags</primary></indexterm><programlisting>typedef enum
224
223
G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG = 1 << 0,
225
224
G_MARKUP_TREAT_CDATA_AS_TEXT = 1 << 1,
227
226
} GMarkupParseFlags;
228
227
</programlisting>
230
Flags that affect the behaviour of the parser.
229
Flags that affect the behaviour of the parser.
231
230
</para><variablelist role="enum">
233
<term><anchor id="G-MARKUP-DO-NOT-USE-THIS-UNSUPPORTED-FLAG:CAPS" role="constant"/><literal>G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG</literal></term>
231
<varlistentry id="G-MARKUP-DO-NOT-USE-THIS-UNSUPPORTED-FLAG--CAPS" role="constant">
232
<term><literal>G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG</literal></term>
234
233
<listitem><simpara>flag you should not use.
235
234
</simpara></listitem>
238
<term><anchor id="G-MARKUP-TREAT-CDATA-AS-TEXT:CAPS" role="constant"/><literal>G_MARKUP_TREAT_CDATA_AS_TEXT</literal></term>
236
<varlistentry id="G-MARKUP-TREAT-CDATA-AS-TEXT--CAPS" role="constant">
237
<term><literal>G_MARKUP_TREAT_CDATA_AS_TEXT</literal></term>
239
238
<listitem><simpara>When this flag is set, CDATA marked
240
239
sections are not passed literally to the <parameter>passthrough</parameter> function of
241
the parser. Instead, the content of the section (without the
240
the parser. Instead, the content of the section (without the
242
241
<literal><![CDATA[</literal> and <literal>]]></literal>) is
243
242
passed to the <parameter>text</parameter> function. This flag was added in GLib 2.12.
244
243
</simpara></listitem>
247
<term><anchor id="G-MARKUP-PREFIX-ERROR-POSITION:CAPS" role="constant"/><literal>G_MARKUP_PREFIX_ERROR_POSITION</literal></term>
245
<varlistentry id="G-MARKUP-PREFIX-ERROR-POSITION--CAPS" role="constant">
246
<term><literal>G_MARKUP_PREFIX_ERROR_POSITION</literal></term>
248
247
<listitem><simpara>Normally errors caught by GMarkup
249
248
itself have line/column information prefixed to them to let the
250
249
caller know the location of the error. When this flag is set the
251
250
location information is also prefixed to errors generated by the
252
251
<link linkend="GMarkupParser"><type>GMarkupParser</type></link> implementation functions.
254
252
</simpara></listitem>
256
254
</variablelist></refsect2>
258
<title><anchor id="GMarkupParseContext" role="struct"/>GMarkupParseContext</title>
259
<indexterm><primary>GMarkupParseContext</primary></indexterm><programlisting>typedef struct _GMarkupParseContext GMarkupParseContext;</programlisting>
255
<refsect2 id="GMarkupParseContext" role="struct">
256
<title>GMarkupParseContext</title>
257
<indexterm zone="GMarkupParseContext"><primary sortas="GMarkupParseContext">GMarkupParseContext</primary></indexterm><programlisting>typedef struct _GMarkupParseContext GMarkupParseContext;</programlisting>
261
259
A parse context is used to parse a stream of bytes that you expect to
262
260
contain marked-up text. See <link linkend="g-markup-parse-context-new"><function>g_markup_parse_context_new()</function></link>,
263
261
<link linkend="GMarkupParser"><type>GMarkupParser</type></link>, and so on for more details.
264
262
</para></refsect2>
266
<title><anchor id="GMarkupParser" role="struct"/>GMarkupParser</title>
267
<indexterm><primary>GMarkupParser</primary></indexterm><programlisting>typedef struct {
263
<refsect2 id="GMarkupParser" role="struct">
264
<title>GMarkupParser</title>
265
<indexterm zone="GMarkupParser"><primary sortas="GMarkupParser">GMarkupParser</primary></indexterm><programlisting>typedef struct {
268
266
/* Called for open tags <foo bar="baz"> */
269
267
void (*start_element) (GMarkupParseContext *context,
270
268
const gchar *element_name,
308
306
</programlisting>
310
Any of the fields in <link linkend="GMarkupParser"><type>GMarkupParser</type></link> can be <link linkend="NULL:CAPS"><literal>NULL</literal></link>, in which case they
308
Any of the fields in <link linkend="GMarkupParser"><type>GMarkupParser</type></link> can be <link linkend="NULL--CAPS"><literal>NULL</literal></link>, in which case they
311
309
will be ignored. Except for the <parameter>error</parameter> function, any of these
312
310
callbacks can set an error; in particular the
313
<link linkend="G-MARKUP-ERROR-UNKNOWN-ELEMENT:CAPS"><literal>G_MARKUP_ERROR_UNKNOWN_ELEMENT</literal></link>, <link linkend="G-MARKUP-ERROR-UNKNOWN-ATTRIBUTE:CAPS"><literal>G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE</literal></link>,
314
and <link linkend="G-MARKUP-ERROR-INVALID-CONTENT:CAPS"><literal>G_MARKUP_ERROR_INVALID_CONTENT</literal></link> errors are intended to be set
311
<link linkend="G-MARKUP-ERROR-UNKNOWN-ELEMENT--CAPS"><literal>G_MARKUP_ERROR_UNKNOWN_ELEMENT</literal></link>, <link linkend="G-MARKUP-ERROR-UNKNOWN-ATTRIBUTE--CAPS"><literal>G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE</literal></link>,
312
and <link linkend="G-MARKUP-ERROR-INVALID-CONTENT--CAPS"><literal>G_MARKUP_ERROR_INVALID_CONTENT</literal></link> errors are intended to be set
315
313
from these callbacks. If you set an error from a callback,
316
314
<link linkend="g-markup-parse-context-parse"><function>g_markup_parse_context_parse()</function></link> will report that error back to its caller.
317
315
</para><variablelist role="struct">
319
<term><structfield>start_element</structfield> ()</term>
317
<term><structfield>start_element</structfield> ()</term>
320
318
<listitem><simpara>Callback to invoke when the opening tag of an element
322
320
</simpara></listitem>
325
<term><structfield>end_element</structfield> ()</term>
323
<term><structfield>end_element</structfield> ()</term>
326
324
<listitem><simpara>Callback to invoke when the closing tag of an element is seen.
327
Note that this is also called for empty tags like
325
Note that this is also called for empty tags like
328
326
<literal><empty/></literal>.
329
327
</simpara></listitem>
332
<term><structfield>text</structfield> ()</term>
330
<term><structfield>text</structfield> ()</term>
333
331
<listitem><simpara>Callback to invoke when some text is seen (text is always
334
332
inside an element). Note that the text of an element may be spread
335
over multiple calls of this function. If the <link linkend="G-MARKUP-TREAT-CDATA-AS-TEXT:CAPS"><literal>G_MARKUP_TREAT_CDATA_AS_TEXT</literal></link>
336
flag is set, this function is also called for the content of CDATA marked
333
over multiple calls of this function. If the <link linkend="G-MARKUP-TREAT-CDATA-AS-TEXT--CAPS"><literal>G_MARKUP_TREAT_CDATA_AS_TEXT</literal></link>
334
flag is set, this function is also called for the content of CDATA marked
338
336
</simpara></listitem>
341
<term><structfield>passthrough</structfield> ()</term>
339
<term><structfield>passthrough</structfield> ()</term>
342
340
<listitem><simpara>Callback to invoke for comments, processing instructions
343
and doctype declarations; if you're re-writing the parsed document,
341
and doctype declarations; if you're re-writing the parsed document,
344
342
write the passthrough text back out in the same position. If the
345
<link linkend="G-MARKUP-TREAT-CDATA-AS-TEXT:CAPS"><literal>G_MARKUP_TREAT_CDATA_AS_TEXT</literal></link> flag is not set, this function is also
343
<link linkend="G-MARKUP-TREAT-CDATA-AS-TEXT--CAPS"><literal>G_MARKUP_TREAT_CDATA_AS_TEXT</literal></link> flag is not set, this function is also
346
344
called for CDATA marked sections.
347
345
</simpara></listitem>
350
<term><structfield>error</structfield> ()</term>
348
<term><structfield>error</structfield> ()</term>
351
349
<listitem><simpara>Callback to invoke when an error occurs.
353
350
</simpara></listitem>
355
352
</variablelist></refsect2>
357
<title><anchor id="g-markup-escape-text" role="function"/>g_markup_escape_text ()</title>
358
<indexterm><primary>g_markup_escape_text</primary></indexterm><programlisting><link linkend="gchar">gchar</link>* g_markup_escape_text (const <link linkend="gchar">gchar</link> *text,
353
<refsect2 id="g-markup-escape-text" role="function">
354
<title>g_markup_escape_text ()</title>
355
<indexterm zone="g-markup-escape-text"><primary sortas="g_markup_escape_text">g_markup_escape_text</primary></indexterm><programlisting><link linkend="gchar">gchar</link>* g_markup_escape_text (const <link linkend="gchar">gchar</link> *text,
359
356
<link linkend="gssize">gssize</link> length);</programlisting>
361
358
Escapes text so that the markup parser will parse it verbatim.
367
364
Note that this function doesn't protect whitespace and line endings
368
365
from being processed according to the XML rules for normalization
369
of line endings and attribute values.</para>
366
of line endings and attribute values.
369
Note also that if given a string containing them, this function
370
will produce character references in the range of &<link linkend="x1"><type>x1</type></link>; ..
371
&<link linkend="x1f"><type>x1f</type></link>; for all control sequences except for tabstop, newline
372
and carriage return. The character references in this range are
373
not valid XML 1.0, but they are valid XML 1.1 and will be accepted
374
by the GMarkup parser.</para>
372
376
</para><variablelist role="params">
373
<varlistentry><term><parameter>text</parameter> :</term>
377
<varlistentry><term><parameter>text</parameter> :</term>
374
378
<listitem><simpara> some valid UTF-8 text
375
379
</simpara></listitem></varlistentry>
376
<varlistentry><term><parameter>length</parameter> :</term>
380
<varlistentry><term><parameter>length</parameter> :</term>
377
381
<listitem><simpara> length of <parameter>text</parameter> in bytes, or -1 if the text is nul-terminated
378
382
</simpara></listitem></varlistentry>
379
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a newly allocated string with the escaped text
383
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a newly allocated string with the escaped text
380
384
</simpara></listitem></varlistentry>
381
385
</variablelist></refsect2>
383
<title><anchor id="g-markup-printf-escaped" role="function" condition="since:2.4"/>g_markup_printf_escaped ()</title>
384
<indexterm role="2.4"><primary>g_markup_printf_escaped</primary></indexterm><programlisting><link linkend="gchar">gchar</link>* g_markup_printf_escaped (const <link linkend="char">char</link> *format,
386
<refsect2 id="g-markup-printf-escaped" role="function" condition="since:2.4">
387
<title>g_markup_printf_escaped ()</title>
388
<indexterm zone="g-markup-printf-escaped" role="2.4"><primary sortas="g_markup_printf_escaped">g_markup_printf_escaped</primary></indexterm><programlisting><link linkend="gchar">gchar</link> * g_markup_printf_escaped (const <link linkend="char">char</link> *format,
385
389
...);</programlisting>
387
391
Formats arguments according to <parameter>format</parameter>, escaping
405
409
</programlisting></informalexample></para>
408
411
</para><variablelist role="params">
409
<varlistentry><term><parameter>format</parameter> :</term>
412
<varlistentry><term><parameter>format</parameter> :</term>
410
413
<listitem><simpara> <link linkend="printf"><function>printf()</function></link> style format string
411
414
</simpara></listitem></varlistentry>
412
<varlistentry><term><parameter>...</parameter> :</term>
415
<varlistentry><term><parameter>...</parameter> :</term>
413
416
<listitem><simpara> the arguments to insert in the format string
414
417
</simpara></listitem></varlistentry>
415
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> newly allocated result from formatting
418
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> newly allocated result from formatting
416
419
operation. Free with <link linkend="g-free"><function>g_free()</function></link>.
418
421
</simpara></listitem></varlistentry>
419
</variablelist><para role="since">Since 2.4
422
<title><anchor id="g-markup-vprintf-escaped" role="function" condition="since:2.4"/>g_markup_vprintf_escaped ()</title>
423
<indexterm role="2.4"><primary>g_markup_vprintf_escaped</primary></indexterm><programlisting><link linkend="gchar">gchar</link>* g_markup_vprintf_escaped (const <link linkend="char">char</link> *format,
422
</variablelist><para role="since">Since 2.4</para></refsect2>
423
<refsect2 id="g-markup-vprintf-escaped" role="function" condition="since:2.4">
424
<title>g_markup_vprintf_escaped ()</title>
425
<indexterm zone="g-markup-vprintf-escaped" role="2.4"><primary sortas="g_markup_vprintf_escaped">g_markup_vprintf_escaped</primary></indexterm><programlisting><link linkend="gchar">gchar</link> * g_markup_vprintf_escaped (const <link linkend="char">char</link> *format,
424
426
<link linkend="va-list">va_list</link> args);</programlisting>
426
428
Formats the data in <parameter>args</parameter> according to <parameter>format</parameter>, escaping
427
429
all string and character arguments in the fashion
428
430
of <link linkend="g-markup-escape-text"><function>g_markup_escape_text()</function></link>. See <link linkend="g-markup-printf-escaped"><function>g_markup_printf_escaped()</function></link>.</para>
431
432
</para><variablelist role="params">
432
<varlistentry><term><parameter>format</parameter> :</term>
433
<varlistentry><term><parameter>format</parameter> :</term>
433
434
<listitem><simpara> <link linkend="printf"><function>printf()</function></link> style format string
434
435
</simpara></listitem></varlistentry>
435
<varlistentry><term><parameter>args</parameter> :</term>
436
<varlistentry><term><parameter>args</parameter> :</term>
436
437
<listitem><simpara> variable argument list, similar to <link linkend="vprintf"><function>vprintf()</function></link>
437
438
</simpara></listitem></varlistentry>
438
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> newly allocated result from formatting
439
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> newly allocated result from formatting
439
440
operation. Free with <link linkend="g-free"><function>g_free()</function></link>.
441
442
</simpara></listitem></varlistentry>
442
</variablelist><para role="since">Since 2.4
445
<title><anchor id="g-markup-parse-context-end-parse" role="function"/>g_markup_parse_context_end_parse ()</title>
446
<indexterm><primary>g_markup_parse_context_end_parse</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link> g_markup_parse_context_end_parse (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context,
443
</variablelist><para role="since">Since 2.4</para></refsect2>
444
<refsect2 id="g-markup-parse-context-end-parse" role="function">
445
<title>g_markup_parse_context_end_parse ()</title>
446
<indexterm zone="g-markup-parse-context-end-parse"><primary sortas="g_markup_parse_context_end_parse">g_markup_parse_context_end_parse</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link> g_markup_parse_context_end_parse (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context,
447
447
<link linkend="GError">GError</link> **error);</programlisting>
449
449
Signals to the <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link> that all data has been
451
451
This function reports an error if the document isn't complete,
452
452
for example if elements are still open.</para>
455
454
</para><variablelist role="params">
456
<varlistentry><term><parameter>context</parameter> :</term>
455
<varlistentry><term><parameter>context</parameter> :</term>
457
456
<listitem><simpara> a <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>
458
457
</simpara></listitem></varlistentry>
459
<varlistentry><term><parameter>error</parameter> :</term>
458
<varlistentry><term><parameter>error</parameter> :</term>
460
459
<listitem><simpara> return location for a <link linkend="GError"><type>GError</type></link>
461
460
</simpara></listitem></varlistentry>
462
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> if an error was set
461
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> on success, <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> if an error was set
463
462
</simpara></listitem></varlistentry>
464
463
</variablelist></refsect2>
466
<title><anchor id="g-markup-parse-context-free" role="function"/>g_markup_parse_context_free ()</title>
467
<indexterm><primary>g_markup_parse_context_free</primary></indexterm><programlisting><link linkend="void">void</link> g_markup_parse_context_free (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context);</programlisting>
464
<refsect2 id="g-markup-parse-context-free" role="function">
465
<title>g_markup_parse_context_free ()</title>
466
<indexterm zone="g-markup-parse-context-free"><primary sortas="g_markup_parse_context_free">g_markup_parse_context_free</primary></indexterm><programlisting><link linkend="void">void</link> g_markup_parse_context_free (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context);</programlisting>
469
468
Frees a <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>. Can't be called from inside
470
one of the <link linkend="GMarkupParser"><type>GMarkupParser</type></link> functions.</para>
469
one of the <link linkend="GMarkupParser"><type>GMarkupParser</type></link> functions. Can't be called while
470
a subparser is pushed.</para>
473
472
</para><variablelist role="params">
474
<varlistentry><term><parameter>context</parameter> :</term>
473
<varlistentry><term><parameter>context</parameter> :</term>
475
474
<listitem><simpara> a <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>
476
475
</simpara></listitem></varlistentry>
477
476
</variablelist></refsect2>
479
<title><anchor id="g-markup-parse-context-get-position" role="function"/>g_markup_parse_context_get_position ()</title>
480
<indexterm><primary>g_markup_parse_context_get_position</primary></indexterm><programlisting><link linkend="void">void</link> g_markup_parse_context_get_position (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context,
477
<refsect2 id="g-markup-parse-context-get-position" role="function">
478
<title>g_markup_parse_context_get_position ()</title>
479
<indexterm zone="g-markup-parse-context-get-position"><primary sortas="g_markup_parse_context_get_position">g_markup_parse_context_get_position</primary></indexterm><programlisting><link linkend="void">void</link> g_markup_parse_context_get_position (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context,
481
480
<link linkend="gint">gint</link> *line_number,
482
481
<link linkend="gint">gint</link> *char_number);</programlisting>
486
485
semantics for what constitutes the "current" line number other than
487
486
"the best number we could come up with for error messages."</para>
490
488
</para><variablelist role="params">
491
<varlistentry><term><parameter>context</parameter> :</term>
489
<varlistentry><term><parameter>context</parameter> :</term>
492
490
<listitem><simpara> a <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>
493
491
</simpara></listitem></varlistentry>
494
<varlistentry><term><parameter>line_number</parameter> :</term>
495
<listitem><simpara> return location for a line number, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>
492
<varlistentry><term><parameter>line_number</parameter> :</term>
493
<listitem><simpara> return location for a line number, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
496
494
</simpara></listitem></varlistentry>
497
<varlistentry><term><parameter>char_number</parameter> :</term>
498
<listitem><simpara> return location for a char-on-line number, or <link linkend="NULL:CAPS"><literal>NULL</literal></link>
495
<varlistentry><term><parameter>char_number</parameter> :</term>
496
<listitem><simpara> return location for a char-on-line number, or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
499
497
</simpara></listitem></varlistentry>
500
498
</variablelist></refsect2>
502
<title><anchor id="g-markup-parse-context-get-element" role="function" condition="since:2.2"/>g_markup_parse_context_get_element ()</title>
503
<indexterm role="2.2"><primary>g_markup_parse_context_get_element</primary></indexterm><programlisting>const <link linkend="gchar">gchar</link>* g_markup_parse_context_get_element (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context);</programlisting>
499
<refsect2 id="g-markup-parse-context-get-element" role="function" condition="since:2.2">
500
<title>g_markup_parse_context_get_element ()</title>
501
<indexterm zone="g-markup-parse-context-get-element" role="2.2"><primary sortas="g_markup_parse_context_get_element">g_markup_parse_context_get_element</primary></indexterm><programlisting>const <link linkend="gchar">gchar</link> * g_markup_parse_context_get_element (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context);</programlisting>
505
503
Retrieves the name of the currently open element.
535
531
would merely return the name of the element that is being
536
532
processed.</para>
539
</para><variablelist role="params">
540
<varlistentry><term><parameter>context</parameter> :</term>
541
<listitem><simpara> a <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>
542
</simpara></listitem></varlistentry>
543
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the element stack, which must not be modified
546
</simpara></listitem></varlistentry>
547
</variablelist></refsect2>
549
<title><anchor id="g-markup-parse-context-new" role="function"/>g_markup_parse_context_new ()</title>
550
<indexterm><primary>g_markup_parse_context_new</primary></indexterm><programlisting><link linkend="GMarkupParseContext">GMarkupParseContext</link>* g_markup_parse_context_new (const <link linkend="GMarkupParser">GMarkupParser</link> *parser,
534
</para><variablelist role="params">
535
<varlistentry><term><parameter>context</parameter> :</term>
536
<listitem><simpara> a <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>
537
</simpara></listitem></varlistentry>
538
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the element stack, which must not be modified
540
</simpara></listitem></varlistentry>
541
</variablelist><para role="since">Since 2.16</para></refsect2>
542
<refsect2 id="g-markup-parse-context-get-user-data" role="function" condition="since:2.18">
543
<title>g_markup_parse_context_get_user_data ()</title>
544
<indexterm zone="g-markup-parse-context-get-user-data" role="2.18"><primary sortas="g_markup_parse_context_get_user_data">g_markup_parse_context_get_user_data</primary></indexterm><programlisting><link linkend="gpointer">gpointer</link> g_markup_parse_context_get_user_data
545
(<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context);</programlisting>
547
Returns the user_data associated with <parameter>context</parameter>. This will either
548
be the user_data that was provided to <link linkend="g-markup-parse-context-new"><function>g_markup_parse_context_new()</function></link>
549
or to the most recent call of <link linkend="g-markup-parse-context-push"><function>g_markup_parse_context_push()</function></link>.</para>
551
</para><variablelist role="params">
552
<varlistentry><term><parameter>context</parameter> :</term>
553
<listitem><simpara> a <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>
554
</simpara></listitem></varlistentry>
555
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the provided user_data. The returned data belongs to
556
the markup context and will be freed when <link linkend="g-markup-context-free"><function>g_markup_context_free()</function></link>
559
</simpara></listitem></varlistentry>
560
</variablelist><para role="since">Since 2.18</para></refsect2>
561
<refsect2 id="g-markup-parse-context-new" role="function">
562
<title>g_markup_parse_context_new ()</title>
563
<indexterm zone="g-markup-parse-context-new"><primary sortas="g_markup_parse_context_new">g_markup_parse_context_new</primary></indexterm><programlisting><link linkend="GMarkupParseContext">GMarkupParseContext</link> * g_markup_parse_context_new (const <link linkend="GMarkupParser">GMarkupParser</link> *parser,
551
564
<link linkend="GMarkupParseFlags">GMarkupParseFlags</link> flags,
552
565
<link linkend="gpointer">gpointer</link> user_data,
553
566
<link linkend="GDestroyNotify">GDestroyNotify</link> user_data_dnotify);</programlisting>
558
571
the parse context can't continue to parse text (you have to free it
559
572
and create a new parse context).</para>
562
574
</para><variablelist role="params">
563
<varlistentry><term><parameter>parser</parameter> :</term>
575
<varlistentry><term><parameter>parser</parameter> :</term>
564
576
<listitem><simpara> a <link linkend="GMarkupParser"><type>GMarkupParser</type></link>
565
577
</simpara></listitem></varlistentry>
566
<varlistentry><term><parameter>flags</parameter> :</term>
578
<varlistentry><term><parameter>flags</parameter> :</term>
567
579
<listitem><simpara> one or more <link linkend="GMarkupParseFlags"><type>GMarkupParseFlags</type></link>
568
580
</simpara></listitem></varlistentry>
569
<varlistentry><term><parameter>user_data</parameter> :</term>
581
<varlistentry><term><parameter>user_data</parameter> :</term>
570
582
<listitem><simpara> user data to pass to <link linkend="GMarkupParser"><type>GMarkupParser</type></link> functions
571
583
</simpara></listitem></varlistentry>
572
<varlistentry><term><parameter>user_data_dnotify</parameter> :</term>
584
<varlistentry><term><parameter>user_data_dnotify</parameter> :</term>
573
585
<listitem><simpara> user data destroy notifier called when the parse context is freed
574
586
</simpara></listitem></varlistentry>
575
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a new <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>
587
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> a new <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>
576
588
</simpara></listitem></varlistentry>
577
589
</variablelist></refsect2>
579
<title><anchor id="g-markup-parse-context-parse" role="function"/>g_markup_parse_context_parse ()</title>
580
<indexterm><primary>g_markup_parse_context_parse</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link> g_markup_parse_context_parse (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context,
590
<refsect2 id="g-markup-parse-context-parse" role="function">
591
<title>g_markup_parse_context_parse ()</title>
592
<indexterm zone="g-markup-parse-context-parse"><primary sortas="g_markup_parse_context_parse">g_markup_parse_context_parse</primary></indexterm><programlisting><link linkend="gboolean">gboolean</link> g_markup_parse_context_parse (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context,
581
593
const <link linkend="gchar">gchar</link> *text,
582
594
<link linkend="gssize">gssize</link> text_len,
583
595
<link linkend="GError">GError</link> **error);</programlisting>
591
603
the process if an error occurs. Once an error is reported, no further
592
604
data may be fed to the <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>; all errors are fatal.</para>
595
606
</para><variablelist role="params">
596
<varlistentry><term><parameter>context</parameter> :</term>
607
<varlistentry><term><parameter>context</parameter> :</term>
597
608
<listitem><simpara> a <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>
598
609
</simpara></listitem></varlistentry>
599
<varlistentry><term><parameter>text</parameter> :</term>
610
<varlistentry><term><parameter>text</parameter> :</term>
600
611
<listitem><simpara> chunk of text to parse
601
612
</simpara></listitem></varlistentry>
602
<varlistentry><term><parameter>text_len</parameter> :</term>
613
<varlistentry><term><parameter>text_len</parameter> :</term>
603
614
<listitem><simpara> length of <parameter>text</parameter> in bytes
604
615
</simpara></listitem></varlistentry>
605
<varlistentry><term><parameter>error</parameter> :</term>
616
<varlistentry><term><parameter>error</parameter> :</term>
606
617
<listitem><simpara> return location for a <link linkend="GError"><type>GError</type></link>
607
618
</simpara></listitem></varlistentry>
608
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> if an error occurred, <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> on success
619
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> if an error occurred, <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> on success
609
620
</simpara></listitem></varlistentry>
610
621
</variablelist></refsect2>
612
<title><anchor id="GMarkupCollectType" role="enum"/>enum GMarkupCollectType</title>
613
<indexterm><primary>GMarkupCollectType</primary></indexterm><programlisting>typedef enum
622
<refsect2 id="g-markup-parse-context-push" role="function" condition="since:2.18">
623
<title>g_markup_parse_context_push ()</title>
624
<indexterm zone="g-markup-parse-context-push" role="2.18"><primary sortas="g_markup_parse_context_push">g_markup_parse_context_push</primary></indexterm><programlisting><link linkend="void">void</link> g_markup_parse_context_push (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context,
625
<link linkend="GMarkupParser">GMarkupParser</link> *parser,
626
<link linkend="gpointer">gpointer</link> user_data);</programlisting>
628
Temporarily redirects markup data to a sub-parser.
631
This function may only be called from the start_element handler of
632
a <link linkend="GMarkupParser"><type>GMarkupParser</type></link>. It must be matched with a corresponding call to
633
<link linkend="g-markup-parse-context-pop"><function>g_markup_parse_context_pop()</function></link> in the matching end_element handler
634
(except in the case that the parser aborts due to an error).
637
All tags, text and other data between the matching tags is
638
redirected to the subparser given by <parameter>parser</parameter>. <parameter>user_data</parameter> is used
639
as the user_data for that parser. <parameter>user_data</parameter> is also passed to the
640
error callback in the event that an error occurs. This includes
641
errors that occur in subparsers of the subparser.
644
The end tag matching the start tag for which this call was made is
645
handled by the previous parser (which is given its own user_data)
646
which is why <link linkend="g-markup-parse-context-pop"><function>g_markup_parse_context_pop()</function></link> is provided to allow "one
647
last access" to the <parameter>user_data</parameter> provided to this function. In the
648
case of error, the <parameter>user_data</parameter> provided here is passed directly to
649
the error callback of the subparser and <link linkend="g-markup-parse-context"><function>g_markup_parse_context()</function></link>
650
should not be called. In either case, if <parameter>user_data</parameter> was allocated
651
then it ought to be freed from both of these locations.
654
This function is not intended to be directly called by users
655
interested in invoking subparsers. Instead, it is intended to be
656
used by the subparsers themselves to implement a higher-level
660
As an example, see the following implementation of a simple
661
parser that counts the number of tags encountered.
664
<informalexample><programlisting>
671
counter_start_element (GMarkupParseContext *context,
672
const gchar *element_name,
673
const gchar **attribute_names,
674
const gchar **attribute_values,
678
CounterData *data = user_data;
684
counter_error (GMarkupParseContext *context,
688
CounterData *data = user_data;
690
g_slice_free (CounterData, data);
693
static GMarkupParser counter_subparser =
695
counter_start_element,
701
</programlisting></informalexample>
704
In order to allow this parser to be easily used as a subparser, the
705
following interface is provided:
708
<informalexample><programlisting>
710
start_counting (GMarkupParseContext *context)
712
CounterData *data = g_slice_new (CounterData);
715
g_markup_parse_context_push (context, &counter_subparser, data);
719
end_counting (GMarkupParseContext *context)
721
CounterData *data = g_markup_parse_context_pop (context);
724
result = data->tag_count;
725
g_slice_free (CounterData, data);
729
</programlisting></informalexample>
732
The subparser would then be used as follows:
735
<informalexample><programlisting>
736
static void start_element (context, element_name, ...)
738
if (strcmp (element_name, "count-these") == 0)
739
start_counting (context);
741
/* else, handle other tags... */
744
static void end_element (context, element_name, ...)
746
if (strcmp (element_name, "count-these") == 0)
747
g_print ("Counted %d tags\n", end_counting (context));
749
/* else, handle other tags... */
751
</programlisting></informalexample></para>
753
</para><variablelist role="params">
754
<varlistentry><term><parameter>context</parameter> :</term>
755
<listitem><simpara> a <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>
756
</simpara></listitem></varlistentry>
757
<varlistentry><term><parameter>parser</parameter> :</term>
758
<listitem><simpara> a <link linkend="GMarkupParser"><type>GMarkupParser</type></link>
759
</simpara></listitem></varlistentry>
760
<varlistentry><term><parameter>user_data</parameter> :</term>
761
<listitem><simpara> user data to pass to <link linkend="GMarkupParser"><type>GMarkupParser</type></link> functions
762
</simpara></listitem></varlistentry>
763
</variablelist><para role="since">Since 2.18</para></refsect2>
764
<refsect2 id="g-markup-parse-context-pop" role="function" condition="since:2.18">
765
<title>g_markup_parse_context_pop ()</title>
766
<indexterm zone="g-markup-parse-context-pop" role="2.18"><primary sortas="g_markup_parse_context_pop">g_markup_parse_context_pop</primary></indexterm><programlisting><link linkend="gpointer">gpointer</link> g_markup_parse_context_pop (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context);</programlisting>
768
Completes the process of a temporary sub-parser redirection.
771
This function exists to collect the user_data allocated by a
772
matching call to <link linkend="g-markup-parse-context-push"><function>g_markup_parse_context_push()</function></link>. It must be called
773
in the end_element handler corresponding to the start_element
774
handler during which <link linkend="g-markup-parse-context-push"><function>g_markup_parse_context_push()</function></link> was called. You
775
must not call this function from the error callback -- the
776
<parameter>user_data</parameter> is provided directly to the callback in that case.
779
This function is not intended to be directly called by users
780
interested in invoking subparsers. Instead, it is intended to be
781
used by the subparsers themselves to implement a higher-level
784
</para><variablelist role="params">
785
<varlistentry><term><parameter>context</parameter> :</term>
786
<listitem><simpara> a <link linkend="GMarkupParseContext"><type>GMarkupParseContext</type></link>
787
</simpara></listitem></varlistentry>
788
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> the user_data passed to <link linkend="g-markup-parse-context-push"><function>g_markup_parse_context_push()</function></link>.
790
</simpara></listitem></varlistentry>
791
</variablelist><para role="since">Since 2.18</para></refsect2>
792
<refsect2 id="GMarkupCollectType" role="enum">
793
<title>enum GMarkupCollectType</title>
794
<indexterm zone="GMarkupCollectType"><primary sortas="GMarkupCollectType">GMarkupCollectType</primary></indexterm><programlisting>typedef enum
615
796
G_MARKUP_COLLECT_INVALID,
616
797
G_MARKUP_COLLECT_STRING,
625
806
A mixed enumerated type and flags field. You must specify one type
626
807
(string, strdup, boolean, tristate). Additionally, you may
627
808
optionally bitwise OR the type with the flag
628
<link linkend="G-MARKUP-COLLECT-OPTIONAL:CAPS"><literal>G_MARKUP_COLLECT_OPTIONAL</literal></link>.
809
<link linkend="G-MARKUP-COLLECT-OPTIONAL--CAPS"><literal>G_MARKUP_COLLECT_OPTIONAL</literal></link>.
631
812
It is likely that this enum will be extended in the future to
632
813
support other types.</para>
635
815
</para><variablelist role="enum">
637
<term><anchor id="G-MARKUP-COLLECT-INVALID:CAPS" role="constant"/><literal>G_MARKUP_COLLECT_INVALID</literal></term>
816
<varlistentry id="G-MARKUP-COLLECT-INVALID--CAPS" role="constant">
817
<term><literal>G_MARKUP_COLLECT_INVALID</literal></term>
638
818
<listitem><simpara> used to terminate the list of attributes
640
820
</simpara></listitem>
643
<term><anchor id="G-MARKUP-COLLECT-STRING:CAPS" role="constant"/><literal>G_MARKUP_COLLECT_STRING</literal></term>
822
<varlistentry id="G-MARKUP-COLLECT-STRING--CAPS" role="constant">
823
<term><literal>G_MARKUP_COLLECT_STRING</literal></term>
644
824
<listitem><simpara> collect the string pointer directly from
645
825
the attribute_values[] array. Expects a
646
826
parameter of type (const char **). If
647
<link linkend="G-MARKUP-COLLECT-OPTIONAL:CAPS"><literal>G_MARKUP_COLLECT_OPTIONAL</literal></link> is specified
827
<link linkend="G-MARKUP-COLLECT-OPTIONAL--CAPS"><literal>G_MARKUP_COLLECT_OPTIONAL</literal></link> is specified
648
828
and the attribute isn't present then the
649
pointer will be set to <link linkend="NULL:CAPS"><literal>NULL</literal></link>.
829
pointer will be set to <link linkend="NULL--CAPS"><literal>NULL</literal></link>.
650
830
</simpara></listitem>
653
<term><anchor id="G-MARKUP-COLLECT-STRDUP:CAPS" role="constant"/><literal>G_MARKUP_COLLECT_STRDUP</literal></term>
654
<listitem><simpara> as with <link linkend="G-MARKUP-COLLECT-STRING:CAPS"><literal>G_MARKUP_COLLECT_STRING</literal></link>, but
832
<varlistentry id="G-MARKUP-COLLECT-STRDUP--CAPS" role="constant">
833
<term><literal>G_MARKUP_COLLECT_STRDUP</literal></term>
834
<listitem><simpara> as with <link linkend="G-MARKUP-COLLECT-STRING--CAPS"><literal>G_MARKUP_COLLECT_STRING</literal></link>, but
655
835
expects a paramter of type (char **) and
656
836
<link linkend="g-strdup"><function>g_strdup()</function></link>s the returned pointer. The
657
837
pointer must be freed with <link linkend="g-free"><function>g_free()</function></link>.
658
838
</simpara></listitem>
661
<term><anchor id="G-MARKUP-COLLECT-BOOLEAN:CAPS" role="constant"/><literal>G_MARKUP_COLLECT_BOOLEAN</literal></term>
840
<varlistentry id="G-MARKUP-COLLECT-BOOLEAN--CAPS" role="constant">
841
<term><literal>G_MARKUP_COLLECT_BOOLEAN</literal></term>
662
842
<listitem><simpara> expects a parameter of type (gboolean *)
663
843
and parses the attribute value as a
664
boolean. Sets <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> if the attribute
844
boolean. Sets <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> if the attribute
665
845
isn't present. Valid boolean values
666
846
consist of (case insensitive) "false",
667
847
"f", "no", "n", "0" and "true", "t",
669
849
</simpara></listitem>
672
<term><anchor id="G-MARKUP-COLLECT-TRISTATE:CAPS" role="constant"/><literal>G_MARKUP_COLLECT_TRISTATE</literal></term>
673
<listitem><simpara> as with <link linkend="G-MARKUP-COLLECT-BOOLEAN:CAPS"><literal>G_MARKUP_COLLECT_BOOLEAN</literal></link>, but
851
<varlistentry id="G-MARKUP-COLLECT-TRISTATE--CAPS" role="constant">
852
<term><literal>G_MARKUP_COLLECT_TRISTATE</literal></term>
853
<listitem><simpara> as with <link linkend="G-MARKUP-COLLECT-BOOLEAN--CAPS"><literal>G_MARKUP_COLLECT_BOOLEAN</literal></link>, but
674
854
in the case of a missing attribute a
675
855
value is set that compares equal to
676
neither <link linkend="FALSE:CAPS"><literal>FALSE</literal></link> nor <link linkend="TRUE:CAPS"><literal>TRUE</literal></link>.
856
neither <link linkend="FALSE--CAPS"><literal>FALSE</literal></link> nor <link linkend="TRUE--CAPS"><literal>TRUE</literal></link>.
677
857
G_MARKUP_COLLECT_OPTIONAL is implied.
678
858
</simpara></listitem>
681
<term><anchor id="G-MARKUP-COLLECT-OPTIONAL:CAPS" role="constant"/><literal>G_MARKUP_COLLECT_OPTIONAL</literal></term>
860
<varlistentry id="G-MARKUP-COLLECT-OPTIONAL--CAPS" role="constant">
861
<term><literal>G_MARKUP_COLLECT_OPTIONAL</literal></term>
682
862
<listitem><simpara> can be bitwise ORed with the other
683
863
fields. If present, allows the
684
864
attribute not to appear. A default
733
913
The pointer should be of the appropriate type
734
914
(see the descriptions under
735
<link linkend="GMarkupCollectType"><type>GMarkupCollectType</type></link>) and may be <link linkend="NULL:CAPS"><literal>NULL</literal></link> in case a
915
<link linkend="GMarkupCollectType"><type>GMarkupCollectType</type></link>) and may be <link linkend="NULL--CAPS"><literal>NULL</literal></link> in case a
736
916
particular attribute is to be allowed but
740
920
This function deals with issuing errors for missing attributes
741
(of type <link linkend="G-MARKUP-ERROR-MISSING-ATTRIBUTE:CAPS"><literal>G_MARKUP_ERROR_MISSING_ATTRIBUTE</literal></link>), unknown attributes
742
(of type <link linkend="G-MARKUP-ERROR-UNKNOWN-ATTRIBUTE:CAPS"><literal>G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE</literal></link>) and duplicate
743
attributes (of type <link linkend="G-MARKUP-ERROR-INVALID-CONTENT:CAPS"><literal>G_MARKUP_ERROR_INVALID_CONTENT</literal></link>) as well
921
(of type <link linkend="G-MARKUP-ERROR-MISSING-ATTRIBUTE--CAPS"><literal>G_MARKUP_ERROR_MISSING_ATTRIBUTE</literal></link>), unknown attributes
922
(of type <link linkend="G-MARKUP-ERROR-UNKNOWN-ATTRIBUTE--CAPS"><literal>G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE</literal></link>) and duplicate
923
attributes (of type <link linkend="G-MARKUP-ERROR-INVALID-CONTENT--CAPS"><literal>G_MARKUP_ERROR_INVALID_CONTENT</literal></link>) as well
744
924
as parse errors for boolean-valued attributes (again of type
745
<link linkend="G-MARKUP-ERROR-INVALID-CONTENT:CAPS"><literal>G_MARKUP_ERROR_INVALID_CONTENT</literal></link>). In all of these cases <link linkend="FALSE:CAPS"><literal>FALSE</literal></link>
925
<link linkend="G-MARKUP-ERROR-INVALID-CONTENT--CAPS"><literal>G_MARKUP_ERROR_INVALID_CONTENT</literal></link>). In all of these cases <link linkend="FALSE--CAPS"><literal>FALSE</literal></link>
746
926
will be returned and <parameter>error</parameter> will be set as appropriate.</para>
749
928
</para><variablelist role="params">
750
<varlistentry><term><parameter>element_name</parameter> :</term>
929
<varlistentry><term><parameter>element_name</parameter> :</term>
751
930
<listitem><simpara> the current tag name
752
931
</simpara></listitem></varlistentry>
753
<varlistentry><term><parameter>attribute_names</parameter> :</term>
932
<varlistentry><term><parameter>attribute_names</parameter> :</term>
754
933
<listitem><simpara> the attribute names
755
934
</simpara></listitem></varlistentry>
756
<varlistentry><term><parameter>attribute_values</parameter> :</term>
935
<varlistentry><term><parameter>attribute_values</parameter> :</term>
757
936
<listitem><simpara> the attribute values
758
937
</simpara></listitem></varlistentry>
759
<varlistentry><term><parameter>error</parameter> :</term>
760
<listitem><simpara> a pointer to a <link linkend="GError"><type>GError</type></link> or <link linkend="NULL:CAPS"><literal>NULL</literal></link>
938
<varlistentry><term><parameter>error</parameter> :</term>
939
<listitem><simpara> a pointer to a <link linkend="GError"><type>GError</type></link> or <link linkend="NULL--CAPS"><literal>NULL</literal></link>
761
940
</simpara></listitem></varlistentry>
762
<varlistentry><term><parameter>first_type</parameter> :</term>
941
<varlistentry><term><parameter>first_type</parameter> :</term>
763
942
<listitem><simpara> the <link linkend="GMarkupCollectType"><type>GMarkupCollectType</type></link> of the
765
944
</simpara></listitem></varlistentry>
766
<varlistentry><term><parameter>first_attr</parameter> :</term>
945
<varlistentry><term><parameter>first_attr</parameter> :</term>
767
946
<listitem><simpara> the name of the first attribute
768
947
</simpara></listitem></varlistentry>
769
<varlistentry><term><parameter>...</parameter> :</term>
948
<varlistentry><term><parameter>...</parameter> :</term>
770
949
<listitem><simpara> a pointer to the storage location of the
771
first attribute (or <link linkend="NULL:CAPS"><literal>NULL</literal></link>), followed by
950
first attribute (or <link linkend="NULL--CAPS"><literal>NULL</literal></link>), followed by
772
951
more types names and pointers, ending
773
with <link linkend="G-MARKUP-COLLECT-INVALID:CAPS"><literal>G_MARKUP_COLLECT_INVALID</literal></link>.
952
with <link linkend="G-MARKUP-COLLECT-INVALID--CAPS"><literal>G_MARKUP_COLLECT_INVALID</literal></link>.
774
953
</simpara></listitem></varlistentry>
775
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> <link linkend="TRUE:CAPS"><literal>TRUE</literal></link> if successful
954
<varlistentry><term><emphasis>Returns</emphasis> :</term><listitem><simpara> <link linkend="TRUE--CAPS"><literal>TRUE</literal></link> if successful
777
956
</simpara></listitem></varlistentry>
778
</variablelist><para role="since">Since 2.16
957
</variablelist><para role="since">Since 2.16</para></refsect2>
787
<refsect1><refsect2 /><refsect2 /></refsect1>