Index: plug-ins/metadata/xmp-encode.c
===================================================================
--- plug-ins/metadata/xmp-encode.c	(revision 27320)
+++ plug-ins/metadata/xmp-encode.c	(working copy)
@@ -32,6 +32,15 @@
 #include "xmp-encode.h"
 #include "xmp-schemas.h"
 
+
+static void  gen_element (GString     *buffer,
+                          gint         indent,
+                          const gchar *prefix,
+                          const gchar *name,
+                          const gchar *value,
+                          ...) G_GNUC_NULL_TERMINATED;
+
+
 static void
 gen_schema_start (GString         *buffer,
                   const XMPSchema *schema)
@@ -47,6 +56,48 @@ gen_schema_end (GString *buffer)
 }
 
 static void
+gen_element (GString     *buffer,
+             gint         indent,
+             const gchar *prefix,
+             const gchar *name,
+             const gchar *value,
+             ...)
+{
+  const gchar *attr_name;
+  const gchar *attr_value;
+  va_list      args;
+
+  while (indent--)
+    g_string_append_c (buffer, ' ');
+
+  g_string_append_printf (buffer, "<%s:%s", prefix, name);
+
+  va_start (args, value);
+
+  while ((attr_name  = va_arg (args, const gchar *)) != NULL &&
+         (attr_value = va_arg (args, const gchar *)) != NULL)
+    {
+      if (*attr_name && *attr_value)
+        g_string_append_printf (buffer, " %s='%s'", attr_name, attr_value);
+    }
+
+  va_end (args);
+
+  if (value && *value)
+    {
+      gchar *escaped_value = g_markup_escape_text (value, -1);
+
+      g_string_append_printf (buffer, ">%s</%s:%s>\n",
+                              escaped_value, prefix, name);
+      g_free (escaped_value);
+    }
+  else
+    {
+      g_string_append (buffer, " />\n");
+    }
+}
+
+static void
 gen_property (GString            *buffer,
               const XMPSchema    *schema,
               const XMPProperty  *property,
@@ -54,7 +105,6 @@ gen_property (GString            *buffer
 {
   gint         i;
   const gchar *ns_prefix;
-  gchar       *escaped_value;
 
   switch (property->type)
     {
@@ -65,12 +115,8 @@ gen_property (GString            *buffer
     case XMP_TYPE_MIME_TYPE:
     case XMP_TYPE_TEXT:
     case XMP_TYPE_RATIONAL:
-      escaped_value = g_markup_escape_text (value_array[0], -1);
-      g_string_append_printf (buffer, "  <%s:%s>%s</%s:%s>\n",
-                              schema->prefix, property->name,
-                              escaped_value,
-                              schema->prefix, property->name);
-      g_free (escaped_value);
+      gen_element (buffer, 2,
+                   schema->prefix, property->name, value_array[0], NULL);
       break;
 
     case XMP_TYPE_LOCALE_BAG:
@@ -81,10 +127,8 @@ gen_property (GString            *buffer
                               schema->prefix, property->name);
       for (i = 0; value_array[i] != NULL; i++)
         {
-          escaped_value = g_markup_escape_text (value_array[i], -1);
-          g_string_append_printf (buffer, "    <rdf:li>%s</rdf:li>\n",
-                                  escaped_value);
-          g_free (escaped_value);
+          gen_element (buffer, 4,
+                       "rdf", "li", value_array[i], NULL);
         }
       g_string_append_printf (buffer, "   </rdf:Bag>\n  </%s:%s>\n",
                               schema->prefix, property->name);
@@ -98,10 +142,8 @@ gen_property (GString            *buffer
                               schema->prefix, property->name);
       for (i = 0; value_array[i] != NULL; i++)
         {
-          escaped_value = g_markup_escape_text (value_array[i], -1);
-          g_string_append_printf (buffer, "    <rdf:li>%s</rdf:li>\n",
-                                  escaped_value);
-          g_free (escaped_value);
+          gen_element (buffer, 4,
+                       "rdf", "li", value_array[i], NULL);
         }
       g_string_append_printf (buffer, "   </rdf:Seq>\n  </%s:%s>\n",
                               schema->prefix, property->name);
@@ -112,19 +154,20 @@ gen_property (GString            *buffer
                               schema->prefix, property->name);
       for (i = 0; value_array[i] != NULL; i += 2)
         {
-          escaped_value = g_markup_escape_text (value_array[i + 1], -1);
-          g_string_append_printf (buffer,
-                                  "    <rdf:li xml:lang='%s'>%s</rdf:li>\n",
-                                  value_array[i], escaped_value);
-          g_free (escaped_value);
+          gen_element (buffer, 4,
+                       "rdf", "li", value_array[i + 1],
+                       "xml:lang", value_array[i],
+                       NULL);
         }
       g_string_append_printf (buffer, "   </rdf:Alt>\n  </%s:%s>\n",
                               schema->prefix, property->name);
       break;
 
     case XMP_TYPE_URI:
-      g_string_append_printf (buffer, "  <%s:%s rdf:resource='%s' />\n",
-                              schema->prefix, property->name, value_array[0]);
+      gen_element (buffer, 2,
+                   schema->prefix, property->name, NULL,
+                   "rdf:resource", value_array[0],
+                   NULL);
       break;
 
     case XMP_TYPE_RESOURCE_REF:
@@ -156,12 +199,8 @@ gen_property (GString            *buffer
       if (value_array[0] && value_array[1])
         for (i = 2; value_array[i] != NULL; i += 2)
           {
-            escaped_value = g_markup_escape_text (value_array[i + 1], -1);
-            g_string_append_printf (buffer, "   <%s:%s>%s</%s:%s>\n",
-                                    ns_prefix, value_array[i],
-                                    escaped_value,
-                                    ns_prefix, value_array[i]);
-            g_free (escaped_value);
+            gen_element (buffer, 3,
+                         ns_prefix, value_array[i], value_array[i + 1], NULL);
           }
       g_string_append_printf (buffer, "  </%s:%s>\n",
                               schema->prefix, property->name);
