function writeXML($name, $array, $level = 0)
 {
     if (empty($array)) {
         //return "\n" . str_repeat('  ',$level) . "<$name />";
         return "";
     }
     if (sotf_Utils::isAssocArray($array)) {
         $retval = "\n" . str_repeat('  ', $level) . "<{$name}>";
         reset($array);
         while (list($key, $value) = each($array)) {
             $type = gettype($value);
             switch ($type) {
                 case 'array':
                     $retval .= sotf_Utils::writeXML($key, $value, $level + 1);
                     break;
                 default:
                     $retval .= "\n" . str_repeat('  ', $level + 1) . "<{$key}>" . htmlspecialchars($value) . "</{$key}>";
             }
         }
         $retval .= "\n" . str_repeat('  ', $level) . "</{$name}>";
     } else {
         reset($array);
         while (list($key, $value) = each($array)) {
             $type = gettype($value);
             switch ($type) {
                 case 'array':
                     $retval .= sotf_Utils::writeXML($name, $value, $level);
                     break;
                 default:
                     $retval .= "\n" . str_repeat('  ', $level) . "<{$name}>" . htmlspecialchars($value) . "</{$name}>";
             }
         }
     }
     return $retval;
 }