📄 glib-simple-xml-subset-parser.html
字号:
data may be fed to the <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext"><span class="type">GMarkupParseContext</span></a>; all errors are fatal.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>context</code></em> :</span></p></td><td> a <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParseContext"><span class="type">GMarkupParseContext</span></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>text</code></em> :</span></p></td><td> chunk of text to parse</td></tr><tr><td><p><span class="term"><em class="parameter"><code>text_len</code></em> :</span></p></td><td> length of <em class="parameter"><code>text</code></em> in bytes</td></tr><tr><td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td><td> return location for a <a class="link" href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a></td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if an error occurred, <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> on success</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3166974"></a><h3><a name="GMarkupCollectType"></a>enum GMarkupCollectType</h3><a class="indexterm" name="id3166987"></a><pre class="programlisting">typedef enum{ G_MARKUP_COLLECT_INVALID, G_MARKUP_COLLECT_STRING, G_MARKUP_COLLECT_STRDUP, G_MARKUP_COLLECT_BOOLEAN, G_MARKUP_COLLECT_TRISTATE, G_MARKUP_COLLECT_OPTIONAL = (1 << 16)} GMarkupCollectType;</pre><p>A mixed enumerated type and flags field. You must specify one type(string, strdup, boolean, tristate). Additionally, you mayoptionally bitwise OR the type with the flag<a class="link" href="glib-Simple-XML-Subset-Parser.html#G-MARKUP-COLLECT-OPTIONAL:CAPS"><code class="literal">G_MARKUP_COLLECT_OPTIONAL</code></a>.</p><p>It is likely that this enum will be extended in the future tosupport other types.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><a name="G-MARKUP-COLLECT-INVALID:CAPS"></a><code class="literal">G_MARKUP_COLLECT_INVALID</code></span></p></td><td> used to terminate the list of attributes to collect.</td></tr><tr><td><p><span class="term"><a name="G-MARKUP-COLLECT-STRING:CAPS"></a><code class="literal">G_MARKUP_COLLECT_STRING</code></span></p></td><td> collect the string pointer directly from the attribute_values[] array. Expects a parameter of type (const char **). If <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 and the attribute isn't present then the pointer will be set to <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>.</td></tr><tr><td><p><span class="term"><a name="G-MARKUP-COLLECT-STRDUP:CAPS"></a><code class="literal">G_MARKUP_COLLECT_STRDUP</code></span></p></td><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 expects a paramter of type (char **) and <a class="link" href="glib-String-Utility-Functions.html#g-strdup"><code class="function">g_strdup()</code></a>s the returned pointer. The pointer must be freed with <a class="link" href="glib-Memory-Allocation.html#g-free"><code class="function">g_free()</code></a>.</td></tr><tr><td><p><span class="term"><a name="G-MARKUP-COLLECT-BOOLEAN:CAPS"></a><code class="literal">G_MARKUP_COLLECT_BOOLEAN</code></span></p></td><td> expects a parameter of type (gboolean *) and parses the attribute value as a boolean. Sets <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> if the attribute isn't present. Valid boolean values consist of (case insensitive) "false", "f", "no", "n", "0" and "true", "t", "yes", "y", "1".</td></tr><tr><td><p><span class="term"><a name="G-MARKUP-COLLECT-TRISTATE:CAPS"></a><code class="literal">G_MARKUP_COLLECT_TRISTATE</code></span></p></td><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 in the case of a missing attribute a value is set that compares equal to neither <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> nor <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a>. G_MARKUP_COLLECT_OPTIONAL is implied.</td></tr><tr><td><p><span class="term"><a name="G-MARKUP-COLLECT-OPTIONAL:CAPS"></a><code class="literal">G_MARKUP_COLLECT_OPTIONAL</code></span></p></td><td> can be bitwise ORed with the other fields. If present, allows the attribute not to appear. A default value is set depending on what value type is used.</td></tr></tbody></table></div></div><hr><div class="refsect2" lang="en"><a name="id3167292"></a><h3><a name="g-markup-collect-attributes"></a>g_markup_collect_attributes ()</h3><a class="indexterm" name="id3167307"></a><pre class="programlisting"><a class="link" href="glib-Basic-Types.html#gboolean">gboolean</a> g_markup_collect_attributes (const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *element_name, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> **attribute_names, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> **attribute_values, <a class="link" href="glib-Error-Reporting.html#GError">GError</a> **error, <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupCollectType">GMarkupCollectType</a> first_type, const <a class="link" href="glib-Basic-Types.html#gchar">gchar</a> *first_attr, ...);</pre><p>Collects the attributes of the element from thedata passed to the <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupParser"><span class="type">GMarkupParser</span></a> start_elementfunction, dealing with common error conditionsand supporting boolean values.</p><p>This utility function is not required to writea parser but can save a lot of typing.</p><p>The <em class="parameter"><code>element_name</code></em>, <em class="parameter"><code>attribute_names</code></em>,<em class="parameter"><code>attribute_values</code></em> and <em class="parameter"><code>error</code></em> parameters passedto the start_element callback should be passedunmodified to this function.</p><p>Following these arguments is a list of"supported" attributes to collect. It is anerror to specify multiple attributes with thesame name. If any attribute not in the listappears in the <em class="parameter"><code>attribute_names</code></em> array then anunknown attribute error will result.</p><p>The <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupCollectType"><span class="type">GMarkupCollectType</span></a> field allows specifyingthe type of collection to perform and if agiven attribute must appear or is optional.</p><p>The attribute name is simply the name of theattribute to collect.</p><p>The pointer should be of the appropriate type(see the descriptions under<a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupCollectType"><span class="type">GMarkupCollectType</span></a>) and may be <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a> in case aparticular attribute is to be allowed butignored.</p><p>This function deals with issuing errors for missing attributes (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 (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 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 as parse errors for boolean-valued attributes (again 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>). In all of these cases <a class="link" href="glib-Standard-Macros.html#FALSE:CAPS"><code class="literal">FALSE</code></a> will be returned and <em class="parameter"><code>error</code></em> will be set as appropriate.</p><p></p><div class="variablelist"><table border="0"><col align="left" valign="top"><tbody><tr><td><p><span class="term"><em class="parameter"><code>element_name</code></em> :</span></p></td><td> the current tag name</td></tr><tr><td><p><span class="term"><em class="parameter"><code>attribute_names</code></em> :</span></p></td><td> the attribute names</td></tr><tr><td><p><span class="term"><em class="parameter"><code>attribute_values</code></em> :</span></p></td><td> the attribute values</td></tr><tr><td><p><span class="term"><em class="parameter"><code>error</code></em> :</span></p></td><td> a pointer to a <a class="link" href="glib-Error-Reporting.html#GError"><span class="type">GError</span></a> or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a></td></tr><tr><td><p><span class="term"><em class="parameter"><code>first_type</code></em> :</span></p></td><td> the <a class="link" href="glib-Simple-XML-Subset-Parser.html#GMarkupCollectType"><span class="type">GMarkupCollectType</span></a> of the first attribute</td></tr><tr><td><p><span class="term"><em class="parameter"><code>first_attr</code></em> :</span></p></td><td> the name of the first attribute</td></tr><tr><td><p><span class="term"><em class="parameter"><code>...</code></em> :</span></p></td><td> a pointer to the storage location of the first attribute (or <a class="link" href="glib-Standard-Macros.html#NULL:CAPS"><code class="literal">NULL</code></a>), followed by more types names and pointers, ending 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>.</td></tr><tr><td><p><span class="term"><span class="emphasis"><em>Returns</em></span> :</span></p></td><td> <a class="link" href="glib-Standard-Macros.html#TRUE:CAPS"><code class="literal">TRUE</code></a> if successful</td></tr></tbody></table></div><p class="since">Since 2.16</p></div></div><div class="refsect1" lang="en"><a name="id3167734"></a><div class="refsect2" lang="en"><a name="id3167736"></a></div><hr><div class="refsect2" lang="en"><a name="id3167737"></a></div></div><div class="footnotes"><br><hr width="100" align="left"><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></div></div></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -