无法使用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:黑屏 我究竟做错了什么?
已邀请:
您的脚本可能在PHP开始标记之前包含不需要的和不可见的字符(如BOM)
浏览器并非仅用于显示任意XML。他们喜欢HTML(可以是XHTML)。目前尚不清楚为什么要浏览器显示这些内容。如果要用于和用户,则应将其格式化为HTML,如果是用于API(服务),则应使用curl / wget / etc对其进行检查,我确定XMl每次都会看起来相同。

要回复问题请先登录注册