无法使用WAMPServer从PHP导出XML
|
我在本地计算机上使用WAMPServer 2.1。我正在尝试创建一个简单的PHP脚本来输出XML文件。如果没有在IE和Chrome上生成错误,我将无法正常运行。在Firefox 4上,它可以工作。
这是PHP:
<?php
main();
function main()
{
header(\"Content-type: application/xml\");
OutputXML(\'xml/login_user_good.xml\');
exit(0);
}
function OutputXML($filename)
{
echo file_get_contents($filename);
}
?>
这是XML文件:
<?xml version=\"1.0\" encoding=\"utf-8\" ?>
<login_user>
<result_code value=\"1\"/>
<error value=\"Invalid username or password\"/>
</login_user>
当我尝试使用IE 8访问PHP脚本时,出现以下错误:
The XML page cannot be displayed Cannot view XML input using style sheet.
Please correct the error and then click the Refresh button, or try again later.
--------------------------------------------------------------------------------
Invalid at the top level of the document. Error processing resource
\'http://localhost/kiamobile/login_user.php\'. Line 1, P...
<?xml version=\"1.0\" encoding=\"utf-8\" ?>
^
在Google Chrome 10上,出现以下错误:
This page contains the following errors:
error on line 1 at column 6: XML declaration allowed only at the start of the document
在Firefox 4上,我得到了格式正确的XML输出。
在任何浏览器上,当我查看源代码时,都可以看到正确的XML。
我尝试了有无显式标头。如果删除对PHP header()函数的调用,则会得到以下结果:
IE 8:与以前相同的错误
Firefox 4:黑屏
Chrome 10:黑屏
同样,如果我在任何浏览器中查看源代码,都可以看到XML。我尝试使用text / html代替application / xml,没有任何效果。
我尝试过直接在PHP代码中生成XML,如下所示:
<?php
main();
function main()
{
header(\"Content-type: application/xml\");
OutputXML();
exit(0);
}
function OutputXML()
{
echo <<<END
<?xml version=\"1.0\" encoding=\"utf-8\" ?>
<login_user>
<result_code value=\"1\"/>
<error value=\"Invalid username or password\"/>
</login_user>
END;
}
?>
当我这样做时,我得到以下结果:
IE 8:相同的错误
Firefox 4:我看到了格式化的XML
Chrome 10:黑屏
我究竟做错了什么?
没有找到相关结果
已邀请:
2 个回复
括宠
锯康