Function

GLibmarkup_collect_attributes

Declaration

gboolean
g_markup_collect_attributes (
  const gchar* element_name,
  const gchar** attribute_names,
  const gchar** attribute_values,
  GError** error,
  GMarkupCollectType first_type,
  const gchar* first_attr,
  ...
)

Description

Collects the attributes of the element from the data passed to the GMarkupParser start_element function, dealing with common error conditions and supporting boolean values.

This utility function is not required to write a parser but can save a lot of typing.

The element_name, attribute_names, attribute_values and error parameters passed to the start_element callback should be passed unmodified to this function.

Following these arguments is a list of “supported” attributes to collect. It is an error to specify multiple attributes with the same name. If any attribute not in the list appears in the attribute_names array then an unknown attribute error will result.

The GMarkupCollectType field allows specifying the type of collection to perform and if a given attribute must appear or is optional.

The attribute name is simply the name of the attribute to collect.

The pointer should be of the appropriate type (see the descriptions under GMarkupCollectType) and may be NULL in case a particular attribute is to be allowed but ignored.

This function deals with issuing errors for missing attributes (of type G_MARKUP_ERROR_MISSING_ATTRIBUTE), unknown attributes (of type G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE) and duplicate attributes (of type G_MARKUP_ERROR_INVALID_CONTENT) as well as parse errors for boolean-valued attributes (again of type G_MARKUP_ERROR_INVALID_CONTENT). In all of these cases FALSE will be returned and error will be set as appropriate.

Available since:2.16

Parameters

element_name const gchar*
 

The current tag name.

 The data is owned by the caller of the function.
 The string is a NUL terminated UTF-8 string.
attribute_names const gchar**
 

The attribute names.

 The data is owned by the caller of the function.
 The string is a NUL terminated UTF-8 string.
attribute_values const gchar**
 

The attribute values.

 The data is owned by the caller of the function.
 The string is a NUL terminated UTF-8 string.
error GError
 

A pointer to a GError or NULL.

 The data is owned by the caller of the function.
first_type GMarkupCollectType
 

The GMarkupCollectType of the first attribute.

first_attr const gchar*
 

The name of the first attribute.

 The data is owned by the caller of the function.
 The string is a NUL terminated UTF-8 string.
... none
 

A pointer to the storage location of the first attribute (or NULL), followed by more types names and pointers, ending with G_MARKUP_COLLECT_INVALID.

Return value

Returns: gboolean
 

TRUE if successful.