[gimp/metadata-wip-rebased] libgimpbase: add gimp_metadata_serialize_to_xml()



commit b1085fa9a6262239f87cbe9a8e013a3476135cea
Author: Michael Natterer <mitch gimp org>
Date:   Tue Oct 22 23:45:49 2013 +0200

    libgimpbase: add gimp_metadata_serialize_to_xml()

 libgimpbase/gimpbase.def   |    1 +
 libgimpbase/gimpmetadata.c |   83 ++++++++++++++++++++++++++++++++++++++++++++
 libgimpbase/gimpmetadata.h |    1 +
 3 files changed, 85 insertions(+), 0 deletions(-)
---
diff --git a/libgimpbase/gimpbase.def b/libgimpbase/gimpbase.def
index 6d87e07..4c79b6a 100644
--- a/libgimpbase/gimpbase.def
+++ b/libgimpbase/gimpbase.def
@@ -56,6 +56,7 @@ EXPORTS
        gimp_metadata_load_from_file
        gimp_metadata_save_to_file
        gimp_metadata_serialize
+       gimp_metadata_serialize_to_xml
        gimp_metadata_set_bits_per_sample
        gimp_metadata_set_pixel_size
        gimp_metadata_set_resolution
diff --git a/libgimpbase/gimpmetadata.c b/libgimpbase/gimpmetadata.c
index 1d0149b..e79a563 100644
--- a/libgimpbase/gimpmetadata.c
+++ b/libgimpbase/gimpmetadata.c
@@ -274,6 +274,89 @@ gimp_metadata_serialize (GExiv2Metadata *metadata)
   return g_string_free (string, FALSE);
 }
 
+/**
+ * Serializing metadata as a string
+ */
+gchar *
+gimp_metadata_serialize_to_xml (GimpMetadata *metadata)
+{
+  GString  *string;
+  gchar   **exif_data = NULL;
+  gchar   **iptc_data = NULL;
+  gchar   **xmp_data  = NULL;
+  gchar    *value;
+  gchar    *escaped;
+  gint      i;
+
+  g_return_val_if_fail (GEXIV2_IS_METADATA (metadata), NULL);
+
+  string = g_string_new (NULL);
+
+  g_string_append (string, "<?xml version='1.0' encoding='UTF-8'?>\n");
+  g_string_append (string, "<metadata>\n");
+
+  exif_data = gexiv2_metadata_get_exif_tags (metadata);
+
+  if (exif_data)
+    {
+      for (i = 0; exif_data[i] != NULL; i++)
+        {
+          value   = gexiv2_metadata_get_tag_string (metadata, exif_data[i]);
+          escaped = g_markup_escape_text (value, -1);
+
+          g_string_append_printf (string, "  <tag name=\"%s\">%s</tag>\n",
+                                  exif_data[i], escaped);
+
+          g_free (escaped);
+          g_free (value);
+        }
+
+      g_strfreev (exif_data);
+    }
+
+  xmp_data = gexiv2_metadata_get_xmp_tags (metadata);
+
+  if (xmp_data)
+    {
+      for (i = 0; xmp_data[i] != NULL; i++)
+        {
+          value   = gexiv2_metadata_get_tag_string (metadata, xmp_data[i]);
+          escaped = g_markup_escape_text (value, -1);
+
+          g_string_append_printf (string, "  <tag name=\"%s\">%s</tag>\n",
+                                  xmp_data[i], escaped);
+
+          g_free (escaped);
+          g_free (value);
+        }
+
+      g_strfreev (xmp_data);
+    }
+
+  iptc_data = gexiv2_metadata_get_iptc_tags (metadata);
+
+  if (iptc_data)
+    {
+      for (i = 0; iptc_data[i] != NULL; i++)
+        {
+          value   = gexiv2_metadata_get_tag_string (metadata, iptc_data[i]);
+          escaped = g_markup_escape_text (value, -1);
+
+          g_string_append_printf (string, "  <tag name=\"%s\">%s</tag>\n",
+                                  iptc_data[i], escaped);
+
+          g_free (escaped);
+          g_free (value);
+        }
+
+      g_strfreev (iptc_data);
+    }
+
+  g_string_append (string, "</metadata>\n");
+
+  return g_string_free (string, FALSE);
+}
+
 /*
  * reads metadata from a physical file
  */
diff --git a/libgimpbase/gimpmetadata.h b/libgimpbase/gimpmetadata.h
index cbddd38..8236e98 100644
--- a/libgimpbase/gimpmetadata.h
+++ b/libgimpbase/gimpmetadata.h
@@ -41,6 +41,7 @@ typedef enum
 
 GimpMetadata * gimp_metadata_deserialize         (const gchar   *metadata_string);
 gchar        * gimp_metadata_serialize           (GimpMetadata  *metadata);
+gchar        * gimp_metadata_serialize_to_xml    (GimpMetadata  *metadata);
 
 GimpMetadata * gimp_metadata_load_from_file      (GFile         *file,
                                                   GError       **error);


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]