Glib有提供一個輕量級的XML parser,不過文件似乎有提到用於非well format的XML文件可能會有些不可預期的問題 ( GMarkup is not guaranteed to signal an error on all invalid XML; the parser may accept documents that an XML parser would not. However, XML documents which are not well-formed are not considered valid GMarkup documents.),幸好我並不挑剔~哈哈
typedef struct {
void (*start_element) (GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer user_data, GError **error);
void (*end_element) (GMarkupParseContext *context, const gchar *element_name, gpointer user_data, GError **error);
void (*text) (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error);
void (*passthrough) (GMarkupParseContext *context, const gchar *passthrough_text, gsize text_len, gpointer user_data, GError**error);
void (*error) (GMarkupParseContext *context, GError *error, gpointer user_data);
} GMarkupParser;
很顯然的這個結構定義了一些function pointer可以讓我們自己要實作的function掛上去。然後呼叫以下函式…
gboolean g_markup_parse_context_parse (GMarkupParseContext *context, const gchar *text, gssize text_len, GError **error);
就會進行XML 解析的動作,很簡單吧~
詳細資料可以參考http://developer.gimp.org/api/2.0/glib/glib-Simple-XML-Subset-Parser.html











