<?php
header('Content-type: text/xml');
$db_host="localhost";
$db_user="root"; //用户名
$db_password="apmsetup"; //密码
$db_name="searchdb"; //数据库名
$link=mysql_connect($db_host,$db_user,$db_password) or die("连接数据库失败");
mysql_query("SET NAMES 'gb2312'",$link); //选择编码,解决mysql的乱码问题
$db=mysql_select_db($db_name,$link);
$table="sh";//表名
$fic = fopen("hotspot.xml", "w");//输出的xml名称,目录需要有写的权限
fwrite($fic, ' <?xml version="1.0"  encoding="GB2312"?>');
fwrite($fic, " <$table>");
$elements =array();
$result = mysql_query("describe $table");
while ($row = mysql_fetch_array($result))
  $elements[] = $row[0];
$result = mysql_query("select * from $table");
$i = 0;
while ($row = mysql_fetch_array($result)){
$i++;
fwrite($fic, " <row num=\"$i\">");
for ($j = 0; $j <count($elements) ; $j++){
fwrite($fic, " <$elements[$j]>".htmlspecialchars($row[$j])." </$elements[$j]>");
}
fwrite($fic, " </row>");
}
fwrite($fic, " </$table>");
mysql_close();
fclose($fic);
?>
********************************总是提示没有顶层元素**********************************无法显示 XML 页。
使用 样式表无法查看 XML 输入。请更正错误然后单击 刷新按钮,或以后重试。
--------------------------------------------------------------------------------XML 文档必须有一个顶层元素。处理资源 'http://localhost/test4.php' 时出错。请问这个错误怎么解决???帮帮忙,尽量说的详细一些,谢谢