glib-compile-resources: Add xml-preparse convert option

This uses g_markup_parse_context_record() and is useful to pre-parse
GtkBuilder files for faster parsing.
diff --git a/gio/glib-compile-resources.c b/gio/glib-compile-resources.c
index 6ce5aec..ceab020 100644
--- a/gio/glib-compile-resources.c
+++ b/gio/glib-compile-resources.c
@@ -220,6 +220,7 @@
       gchar *key;
       FileData *data = NULL;
       char *tmp_file = NULL;
+      gboolean xml_preparse = FALSE;
 
       file = state->string->str;
       key = file;
@@ -283,6 +284,8 @@
             {
               if (!strcmp (options[i], "xml-stripblanks"))
                 xml_stripblanks = TRUE;
+              else if (!strcmp (options[i], "xml-preparse"))
+                xml_preparse = TRUE;
               else if (!strcmp (options[i], "to-pixdata"))
                 to_pixdata = TRUE;
               else if (!strcmp (options[i], "json-stripblanks"))
@@ -465,6 +468,24 @@
       /* Include zero termination in content_size for uncompressed files (but not in size) */
       data->content_size = data->size + 1;
 
+      if (xml_preparse)
+        {
+          GBytes *preparsed = g_markup_parse_context_record (G_MARKUP_TREAT_CDATA_AS_TEXT,
+                                                             data->content, data->size, &my_error);
+          if (preparsed == NULL)
+            {
+              g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
+                           _("Error pre-parsing xml file %s: %s"),
+                           real_file, my_error->message);
+              g_clear_error (&my_error);
+              goto cleanup;
+            }
+
+          g_free (data->content);
+          data->content = g_bytes_unref_to_data (preparsed, &data->size);
+          data->content_size = data->size;
+        }
+
       if (state->compressed)
 	{
 	  GOutputStream *out = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);