Index: drupal/includes/common.inc
diff -u drupal/includes/common.inc:1.1.2.3 drupal/includes/common.inc:1.1.2.3.2.2
--- drupal/includes/common.inc:1.1.2.3	Mon Apr  5 13:09:44 2004
+++ drupal/includes/common.inc	Thu Apr  8 18:47:48 2004
@@ -746,21 +746,68 @@
   return $output;
 }
 
-function format_rss_item($title, $link, $description, $args = array()) {
-  // arbitrary elements may be added using the $args associative array
+function format_rss_item($node, $version) {
+  $item->title[] = drupal_specialchars(strip_tags($node->title));
+  $item->link[] = drupal_specialchars(strip_tags(url("node/view/$node->nid", NULL, NULL, 1)));
+  $item->description[] = drupal_specialchars(check_output($node->teaser ? $node->teaser : $node->body));
+  $item->pubDate[] = date('r', $item->changed);
+  // TODO: call new hook here (version argument will be used)
+  $xml->item[] = $item;
+  return format_simplexml($xml);
+}
 
-  $output = "<item>\n";
-  $output .= " <title>". drupal_specialchars(strip_tags($title)) ."</title>\n";
-  $output .= " <link>". drupal_specialchars(strip_tags($link)) ."</link>\n";
-  $output .= " <description>". drupal_specialchars(check_output($description)) ."</description>\n";
-  foreach ($args as $key => $value) {
-    $output .= "<$key>". drupal_specialchars(strip_tags($value)) ."</$key>";
+/**
+ * This is a workaround for PHP 4's lack of good XML generation. It is modeled
+ * after the upcoming SimpleXML library in PHP 5
+ * (http://www.php.net/manual/en/ref.simplexml.php). One important difference
+ * is that children of an element should be in the associaive array with
+ * integers for keys. This is necessary because, in PHP 4, an associatie array
+ * (which stores attributes) can not also have a property.
+ *
+ * @param $xml The SimpleXML-fomratted object
+ * @return String of indented XML
+ */
+function format_simplexml($xml) {
+  foreach (get_object_vars($xml) as $name => $tag) {
+    $output .= _format_simplexml_tag($tag, $name, "");
   }
-  $output .= "</item>\n";
-
   return $output;
 }
 
+function _format_simplexml_tag($xml, $name, $indent) {
+  $result = "$indent<$name";
+  $children = array();
+  foreach ($xml as $attr => $value) {
+    if (is_int($attr)) {
+      $children[] = $value;
+    }
+    else {
+      $result .= " $attr=\"$value\"";
+    }
+  }
+  if (count($children) == 1 && !is_object($child = reset($children))) {
+    $result .= ">$child</$name>\n";
+  }
+  else if (count($children) > 0) {
+    $result .= ">\n";
+    foreach ($children as $child) {
+      if (is_object($child)) {
+        foreach (get_object_vars($child) as $tagname => $tag) {
+          $result .= _format_simplexml_tag($tag, $tagname, " $indent");
+        }
+      }
+      else {
+        $result .= " $indent$child\n";
+      }
+    }
+    $result .= "$indent</$name>\n";
+  }
+  else {
+    $result .= " />\n";
+  }
+  return $result;
+}
+
 /**
  * Formats a string with a count of items so that the string is pluralized
  * correctly. format_plural calls t() by itself, make sure not to pass already
Index: drupal/modules/node.module
diff -u drupal/modules/node.module:1.1.2.4 drupal/modules/node.module:1.1.2.4.2.2
--- drupal/modules/node.module:1.1.2.4	Wed Apr  7 09:25:26 2004
+++ drupal/modules/node.module	Thu Apr  8 21:15:41 2004
@@ -1002,16 +1002,6 @@
     $nodes = db_query_range('SELECT nid FROM {node} WHERE promote = 1 AND status = 1 ORDER BY created DESC', 0, 15);
   }
 
-  while ($node = db_fetch_object($nodes)) {
-    /*
-    ** Load the specified node:
-    */
-
-    $item = node_load(array('nid' => $node->nid));
-    $link = url("node/view/$node->nid", NULL, NULL, 1);
-    $items .= format_rss_item($item->title, $link, ($item->teaser ? $item->teaser : $item->body), array('pubDate' => date('r', $item->changed)));
-  }
-
   $channel_defaults = array(
     'version'     => '0.92',
     'title'       => variable_get('site_name', 'drupal') .' - '. variable_get('site_slogan', ''),
@@ -1021,6 +1011,10 @@
   );
   $channel = array_merge($channel_defaults, $channel);
 
+  while ($node = db_fetch_object($nodes)) {
+    $items .= format_rss_item(node_load(array('nid' => $node->nid)), $channel["version"]);
+  }
+
   $output = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n";
   $output .= "<!DOCTYPE rss [<!ENTITY % HTMLlat1 PUBLIC \"-//W3C//ENTITIES Latin 1 for XHTML//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml-lat1.ent\">]>\n";
   $output .= "<rss version=\"". $channel["version"] . "\" xml:base=\"". $base_url ."\">\n";
