2.25.0
[platform/upstream/glib.git] / docs / reference / glib / tmpl / markup.sgml
1 <!-- ##### SECTION Title ##### -->
2 Simple XML Subset Parser
3
4 <!-- ##### SECTION Short_Description ##### -->
5 parses a subset of XML
6
7 <!-- ##### SECTION Long_Description ##### -->
8 <para>
9 The "GMarkup" parser is intended to parse a simple markup format
10 that's a subset of XML. This is a small, efficient, easy-to-use
11 parser. It should not be used if you expect to interoperate with other 
12 applications generating full-scale XML. However, it's very useful for
13 application data files, config files, etc. where you know your
14 application will be the only one writing the file. Full-scale XML
15 parsers should be able to parse the subset used by GMarkup, so you can
16 easily migrate to full-scale XML at a later time if the need arises.
17 </para>
18
19 <para>
20 GMarkup is not guaranteed to signal an error on all invalid XML; the
21 parser may accept documents that an XML parser would not. However, XML 
22 documents which are not well-formed<footnote id="wellformed">Being wellformed
23 is a weaker condition than being valid. See the 
24 <ulink url="http://www.w3.org/TR/REC-xml/">XML specification</ulink> for 
25 definitions of these terms.</footnote> are not considered valid GMarkup 
26 documents. 
27 </para>
28
29 <para>
30 Simplifications to XML include:
31 <itemizedlist>
32 <listitem>
33 <para>
34 Only UTF-8 encoding is allowed.
35 </para>
36 </listitem>
37 <listitem>
38 <para>
39 No user-defined entities.
40 </para>
41 </listitem>
42 <listitem>
43 <para>
44 Processing instructions, comments and the doctype declaration are "passed 
45 through" but are not interpreted in any way.
46 </para>
47 </listitem>
48 <listitem>
49 <para>
50 No DTD or validation.
51 </para>
52 </listitem>
53 </itemizedlist>
54 </para>
55
56 <para>
57 The markup format does support:
58 <itemizedlist>
59 <listitem>
60 <para>
61 Elements
62 </para>
63 </listitem>
64 <listitem>
65 <para>
66 Attributes
67 </para>
68 </listitem>
69 <listitem>
70 <para>
71 5 standard entities: <literal>&amp;amp; &amp;lt; &amp;gt; &amp;quot; &amp;apos;</literal>
72 </para>
73 </listitem>
74 <listitem>
75 <para>
76 Character references
77 </para>
78 </listitem>
79 <listitem>
80 <para>
81 Sections marked as CDATA
82 </para>
83 </listitem>
84 </itemizedlist>
85 </para>
86
87 <!-- ##### SECTION See_Also ##### -->
88 <para>
89
90 </para>
91
92 <!-- ##### SECTION Stability_Level ##### -->
93
94
95 <!-- ##### SECTION Image ##### -->
96
97
98 <!-- ##### ENUM GMarkupError ##### -->
99 <para>
100 Error codes returned by markup parsing.
101 </para>
102
103 @G_MARKUP_ERROR_BAD_UTF8: text being parsed was not valid UTF-8
104 @G_MARKUP_ERROR_EMPTY: document contained nothing, or only whitespace
105 @G_MARKUP_ERROR_PARSE: document was ill-formed
106 @G_MARKUP_ERROR_UNKNOWN_ELEMENT: error should be set by #GMarkupParser functions; element wasn't known
107 @G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE: error should be set by #GMarkupParser functions; attribute wasn't known
108 @G_MARKUP_ERROR_INVALID_CONTENT: error should be set by #GMarkupParser functions; content was invalid
109 @G_MARKUP_ERROR_MISSING_ATTRIBUTE: error should be set by #GMarkupParser functions; a required attribute was missing
110
111 <!-- ##### MACRO G_MARKUP_ERROR ##### -->
112 <para>
113 Error domain for markup parsing. Errors in this domain will
114 be from the #GMarkupError enumeration. See #GError for information on 
115 error domains.
116 </para>
117
118
119
120 <!-- ##### ENUM GMarkupParseFlags ##### -->
121 <para>
122 Flags that affect the behaviour of the parser. 
123 </para>
124
125 @G_MARKUP_DO_NOT_USE_THIS_UNSUPPORTED_FLAG: flag you should not use.
126 @G_MARKUP_TREAT_CDATA_AS_TEXT: When this flag is set, CDATA marked
127   sections are not passed literally to the @passthrough function of
128   the parser. Instead, the content of the section (without the 
129   <literal>&lt;![CDATA[</literal> and <literal>]]&gt;</literal>) is
130   passed to the @text function. This flag was added in GLib 2.12.
131 @G_MARKUP_PREFIX_ERROR_POSITION: Normally errors caught by GMarkup
132   itself have line/column information prefixed to them to let the
133   caller know the location of the error.  When this flag is set the
134   location information is also prefixed to errors generated by the
135   #GMarkupParser implementation functions.
136
137 <!-- ##### STRUCT GMarkupParseContext ##### -->
138 <para>
139 A parse context is used to parse a stream of bytes that you expect to
140 contain marked-up text. See g_markup_parse_context_new(),
141 #GMarkupParser, and so on for more details.
142 </para>
143
144
145 <!-- ##### STRUCT GMarkupParser ##### -->
146 <para>
147 Any of the fields in #GMarkupParser can be %NULL, in which case they
148 will be ignored. Except for the @error function, any of these
149 callbacks can set an error; in particular the
150 %G_MARKUP_ERROR_UNKNOWN_ELEMENT, %G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE,
151 and %G_MARKUP_ERROR_INVALID_CONTENT errors are intended to be set 
152 from these callbacks. If you set an error from a callback,
153 g_markup_parse_context_parse() will report that error back to its caller.
154 </para>
155
156 @start_element: Callback to invoke when the opening tag of an element
157     is seen.
158 @end_element: Callback to invoke when the closing tag of an element is seen.
159     Note that this is also called for empty tags like 
160     <literal>&lt;empty/&gt;</literal>.
161 @text: Callback to invoke when some text is seen (text is always
162     inside an element). Note that the text of an element may be spread
163     over multiple calls of this function. If the %G_MARKUP_TREAT_CDATA_AS_TEXT
164     flag is set, this function is also called for the content of CDATA marked 
165     sections.
166 @passthrough: Callback to invoke for comments, processing instructions 
167     and doctype declarations; if you're re-writing the parsed document, 
168     write the passthrough text back out in the same position. If the
169     %G_MARKUP_TREAT_CDATA_AS_TEXT flag is not set, this function is also 
170     called for CDATA marked sections.
171 @error: Callback to invoke when an error occurs.
172
173 <!-- ##### FUNCTION g_markup_escape_text ##### -->
174 <para>
175
176 </para>
177
178 @text: 
179 @length: 
180 @Returns: 
181
182
183 <!-- ##### FUNCTION g_markup_printf_escaped ##### -->
184 <para>
185
186 </para>
187
188 @format: 
189 @Varargs: 
190 @Returns: 
191
192
193 <!-- ##### FUNCTION g_markup_vprintf_escaped ##### -->
194 <para>
195
196 </para>
197
198 @format: 
199 @args: 
200 @Returns: 
201
202
203 <!-- ##### FUNCTION g_markup_parse_context_end_parse ##### -->
204 <para>
205
206 </para>
207
208 @context: 
209 @error: 
210 @Returns: 
211
212
213 <!-- ##### FUNCTION g_markup_parse_context_free ##### -->
214 <para>
215
216 </para>
217
218 @context: 
219
220
221 <!-- ##### FUNCTION g_markup_parse_context_get_position ##### -->
222 <para>
223
224 </para>
225
226 @context: 
227 @line_number: 
228 @char_number: 
229
230
231 <!-- ##### FUNCTION g_markup_parse_context_get_element ##### -->
232 <para>
233
234 </para>
235
236 @context: 
237 @Returns: 
238
239
240 <!-- ##### FUNCTION g_markup_parse_context_get_element_stack ##### -->
241 <para>
242
243 </para>
244
245 @context: 
246 @Returns: 
247
248
249 <!-- ##### FUNCTION g_markup_parse_context_get_user_data ##### -->
250 <para>
251
252 </para>
253
254 @context: 
255 @Returns: 
256
257
258 <!-- ##### FUNCTION g_markup_parse_context_new ##### -->
259 <para>
260
261 </para>
262
263 @parser: 
264 @flags: 
265 @user_data: 
266 @user_data_dnotify: 
267 @Returns: 
268
269
270 <!-- ##### FUNCTION g_markup_parse_context_parse ##### -->
271 <para>
272
273 </para>
274
275 @context: 
276 @text: 
277 @text_len: 
278 @error: 
279 @Returns: 
280
281
282 <!-- ##### FUNCTION g_markup_parse_context_push ##### -->
283 <para>
284
285 </para>
286
287 @context: 
288 @parser: 
289 @user_data: 
290
291
292 <!-- ##### FUNCTION g_markup_parse_context_pop ##### -->
293 <para>
294
295 </para>
296
297 @context: 
298 @Returns: 
299
300
301 <!-- ##### ENUM GMarkupCollectType ##### -->
302 <para>
303
304 </para>
305
306 @G_MARKUP_COLLECT_INVALID: 
307 @G_MARKUP_COLLECT_STRING: 
308 @G_MARKUP_COLLECT_STRDUP: 
309 @G_MARKUP_COLLECT_BOOLEAN: 
310 @G_MARKUP_COLLECT_TRISTATE: 
311 @G_MARKUP_COLLECT_OPTIONAL: 
312
313 <!-- ##### FUNCTION g_markup_collect_attributes ##### -->
314 <para>
315
316 </para>
317
318 @element_name: 
319 @attribute_names: 
320 @attribute_values: 
321 @error: 
322 @first_type: 
323 @first_attr: 
324 @Varargs: 
325 @Returns: 
326
327