## GDataParsable GDataParsable — GData parsable object |

## Stability Level

Unstable, unless otherwise indicated

## Synopsis

    #include <gdata/gdata-parsable.h>

                        GDataParsable;
                        GDataParsableClass;
    GDataParsable *     gdata_parsable_new_from_xml         (GType parsable_type,
                                                             const gchar *xml,
                                                             gint length,
                                                             GError **error);
    gchar *             gdata_parsable_get_xml              (GDataParsable *self);

## Object Hierarchy

      GObject
       +----GDataParsable
             +----GDataEntry
             +----GDataAPPCategories
             +----GDataAuthor
             +----GDataFeed
             +----GDataCategory
             +----GDataGContactCalendar
             +----GDataGContactEvent
             +----GDataGContactExternalID
             +----GDataGContactJot
             +----GDataGContactLanguage
             +----GDataGContactRelation
             +----GDataGContactWebsite
             +----GDataGDEmailAddress
             +----GDataGDIMAddress
             +----GDataGDName
             +----GDataGDOrganization
             +----GDataGDPhoneNumber
             +----GDataGDPostalAddress
             +----GDataGDReminder
             +----GDataGDWhen
             +----GDataGDWhere
             +----GDataGDWho
             +----GDataGenerator
             +----GDataLink
             +----GDataMediaCategory
             +----GDataMediaContent
             +----GDataMediaCredit
             +----GDataMediaThumbnail
             +----GDataYouTubeState

## Properties

      "constructed-from-xml"     gboolean              : Read / Write / Construct Only

## Description

GDataParsable is an abstract class allowing easy implementation of an extensible parser. It is primarily extended by GDataFeed and GDataEntry, both of which require XML parsing which can be extended by subclassing.

It allows methods to be defined for handling the root XML node, each of its child nodes, and a method to be called after parsing is complete.

## Details

### GDataParsable

    typedef struct _GDataParsable GDataParsable;

All the fields in the GDataParsable structure are private and should never be accessed directly.

Since 0.3.0

### GDataParsableClass

    typedef struct {
    	GObjectClass parent;

    	gboolean (*pre_parse_xml) (GDataParsable *parsable, xmlDoc *doc, xmlNode *root_node, gpointer user_data, GError **error);
    	gboolean (*parse_xml) (GDataParsable *parsable, xmlDoc *doc, xmlNode *node, gpointer user_data, GError **error);
    	gboolean (*post_parse_xml) (GDataParsable *parsable, gpointer user_data, GError **error);

    	void (*pre_get_xml) (GDataParsable *parsable, GString *xml_string);
    	void (*get_xml) (GDataParsable *parsable, GString *xml_string);
    	void (*get_namespaces) (GDataParsable *parsable, GHashTable *namespaces);

    	const gchar *element_name;
    	const gchar *element_namespace;
    } GDataParsableClass;

The class structure for the GDataParsable class.

GObjectClass `parent`; | the parent class
`pre_parse_xml` () | a function called before parsing of an XML tree is started, which allows properties from the root node to be extracted and used in `parsable`
`parse_xml` () | a function to parse an XML representation of the GDataParsable to set the properties of the `parsable`
`post_parse_xml` () | a function called after parsing an XML tree, to allow the `parsable` to validate the parsed properties
`pre_get_xml` () | a function called before building the XML representation of the children of the GDataParsable, which allows attributes of the root XML node to be added to `xml_string`
`get_xml` () | a function to build an XML representation of the GDataParsable in its current state, appending it to the provided GString
`get_namespaces` () | a function to return a string containing the namespace declarations used by the `parsable` when represented in XML form
const gchar *`element_name`; | the name of the XML element which represents this parsable
const gchar *`element_namespace`; | the prefix of the XML namespace used for the parsable

Since 0.3.0

### gdata_parsable_new_from_xml ()

    GDataParsable *     gdata_parsable_new_from_xml         (GType parsable_type,
                                                             const gchar *xml,
                                                             gint length,
                                                             GError **error);

Creates a new GDataParsable subclass (of the given `parsable_type`) from the given `xml`.

An object of the given `parsable_type` is created, and its `pre_parse_xml`, `parse_xml` and `post_parse_xml` class functions called on the XML tree obtained from `xml`. `pre_parse_xml` and `post_parse_xml` are called once each on the root node of the tree, while `parse_xml` is called for each of the child nodes of the root node.

If `length` is -1, `xml` will be assumed to be null-terminated.

If an error occurs during parsing, a suitable error from GDataParserError will be returned.

`parsable_type` : | the type of the class represented by the XML
`xml` : | the XML for just the parsable object, with full namespace declarations
`length` : | the length of `xml`, or -1
`error` : | a GError, or `NULL`
Returns : | a new GDataParsable, or `NULL`; unref with `g_object_unref()`

Since 0.4.0

### gdata_parsable_get_xml ()

    gchar *             gdata_parsable_get_xml              (GDataParsable *self);

Builds an XML representation of the GDataParsable in its current state, such that it could be inserted on the server. The XML is guaranteed to have all its namespaces declared properly in a self-contained fashion, and is valid for stand-alone use.

`self` : | a GDataParsable
Returns : | the object's XML; free with `g_free()`

Since 0.4.0

## Property Details

### The `"constructed-from-xml"` property

      "constructed-from-xml"     gboolean              : Read / Write / Construct Only

Specifies whether the object was constructed by parsing XML or manually.

Default value: FALSE

Since 0.7.0