Index: includes/common.inc
===================================================================
RCS file: /cvs/drupal/drupal/includes/common.inc,v
retrieving revision 1.546
diff -u -r1.546 common.inc
--- includes/common.inc	10 Jul 2006 08:12:31 -0000	1.546
+++ includes/common.inc	17 Jul 2006 14:51:28 -0000
@@ -717,9 +717,7 @@
   // escaped source data (such as &amp becoming &amp;amp;).
   $output .= ' <description>'. check_plain(decode_entities(strip_tags($description))) ."</description>\n";
   $output .= ' <language>'. check_plain($language) ."</language>\n";
-  foreach ($args as $key => $value) {
-    $output .= ' <'. $key .'>'. check_plain($value) ."</$key>\n";
-  }
+  $output .= format_xml_elements($args);
   $output .= $items;
   $output .= "</channel>\n";
 
@@ -736,16 +734,37 @@
   $output .= ' <title>'. check_plain($title) ."</title>\n";
   $output .= ' <link>'. check_url($link) ."</link>\n";
   $output .= ' <description>'. check_plain($description) ."</description>\n";
-  foreach ($args as $key => $value) {
-    if (is_array($value)) {
+  $output .= format_xml_elements($args);
+  $output .= "</item>\n";
+
+  return $output;
+}
+
+/**
+ * Format XML elements.
+ *
+ * @param $array
+ *   An array where each item represent an element and is either a:
+ *   - (key => value) pair (<key>value</key>)
+ *   - Associative array with fields:
+ *     - 'key': element name
+ *     - 'value': element contents
+ *     - 'attributes': associative array of element attributes
+ *
+ * In both cases, 'value' can be a simple string, or it can be another array
+ * with the same format as $array itself for nesting.
+ */
+function format_xml_elements($array) {
+  foreach ($array as $key => $value) {
+    if (is_numeric($key)) {
       if ($value['key']) {
         $output .= ' <'. $value['key'];
         if (isset($value['attributes']) && is_array($value['attributes'])) {
           $output .= drupal_attributes($value['attributes']);
         }
 
-        if ($value['value']) {
-          $output .= '>'. $value['value'] .'</'. $value['key'] .">\n";
+        if ($value['value'] != '') {
+          $output .= '>'. (is_array($value['value']) ? format_xml_tags($value['value']) : check_plain($value['value'])) .'</'. $value['key'] .">\n";
         }
         else {
           $output .= " />\n";
@@ -753,11 +772,9 @@
       }
     }
     else {
-      $output .= ' <'. $key .'>'. check_plain($value) ."</$key>\n";
+      $output .= ' <'. $key .'>'. (is_array($value) ? format_xml_tags($value) : check_plain($value)) ."</$key>\n";
     }
   }
-  $output .= "</item>\n";
-
   return $output;
 }
 
