From 5e43e2ef30c178c13a81aaafeacd06b3e8cd7a65 Mon Sep 17 00:00:00 2001 From: Marcel Holtmann Date: Sat, 20 Jan 2007 16:56:52 +0000 Subject: Add example of GLib based parser --- common/sdp-glib.c | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) (limited to 'common/sdp-glib.c') diff --git a/common/sdp-glib.c b/common/sdp-glib.c index 15212994..fa0e8a17 100644 --- a/common/sdp-glib.c +++ b/common/sdp-glib.c @@ -27,9 +27,37 @@ #include +#include "logging.h" #include "sdp-xml.h" +static void element_start(GMarkupParseContext *context, + const gchar *element_name, const gchar **attribute_names, + const gchar **attribute_values, gpointer user_data, GError **error) +{ + debug("<%s>", element_name); +} + +static void element_end(GMarkupParseContext *context, + const gchar *element_name, gpointer user_data, GError **error) +{ + debug("", element_name); +} + +static GMarkupParser parser = { + element_start, element_end, NULL, NULL, NULL +}; + sdp_record_t *sdp_xml_parse_record(const char *data, int size) { + GMarkupParseContext *ctx; + + ctx = g_markup_parse_context_new(&parser, 0, NULL, NULL); + + if (g_markup_parse_context_parse(ctx, data, size, NULL) == FALSE) { + error("XML parsing error"); + } + + g_markup_parse_context_free(ctx); + return NULL; } -- cgit