diff --git a/xmlsitemap.xmlsitemap.inc b/xmlsitemap.xmlsitemap.inc
index 478dd9c..99f42ae 100644
--- a/xmlsitemap.xmlsitemap.inc
+++ b/xmlsitemap.xmlsitemap.inc
@@ -117,21 +117,25 @@ class XMLSitemapWriter extends XMLWriter {
   /**
    * Write full element tag including support for nested elements.
    *
-   * @param $name
+   * @param string $name
    *   The element name.
-   * @param $content
+   * @param string|array $content
    *   The element contents or an array of the elements' sub-elements.
+   *
+   * @return bool
+   *   TRUE on success or FALSE on failure.
    */
-  public function writeElement($name, $content = '') {
+  public function writeElement($name, $content) {
     if (is_array($content)) {
-      $this->startElement($name);
-      foreach ($content as $sub_name => $sub_content) {
-        $this->writeElement($sub_name, $sub_content);
-      }
-      $this->endElement();
+      $return = $this->startElement($name);
+      $xml_content = format_xml_elements($content);
+      $xml_content = str_replace(array(" <", ">\n"), array("<", ">"), $xml_content);
+      $return &= $this->writeRaw($xml_content);
+      $return &= $this->endElement();
+      return $return;
     }
     else {
-      parent::writeElement($name, $content);
+      return parent::writeElement($name, $content);
     }
   }
 
