2014-01-20 38 views
0

我的服務器上有一個XML文件,它駐留在私人位置,因此無法通過URL訪問文件。我正在嘗試使用PHP讀取XML文件的內容,並希望將其顯示在HTML頁面中。我嘗試了幾種方法,例如設置header('Content-type: text/xml'),但似乎沒有任何工作。頁面顯示爲空白文本。我想要顯示XML文件,類似於它在瀏覽器中顯示的方式。使用PHP在HTML頁面中嵌入XML代碼

我必須顯示的XML是這樣的。

<simplexmlresult version="1.3" xmlns="http://sdk.prometric.com/schemas/SimpleXMLResults1_3"> 
<demographics> 
    <demographic name="Activity" value="5"></demographic> 
    <demographic name="AddUser" value="20130000"></demographic> 
</demographics> 
<exam resourcefilename="73392.cer" resourceversion="1.0" name="temp"></exam> 
</simplexmlresult> 

閱讀文件的PHP代碼: -

<?php 
header("Content-type: text/xml; charset=utf-8"); 
error_reporting(E_ALL); 
ini_set('display_errors', TRUE); 
ini_set('display_startup_errors', TRUE); 
$elig_id = $_GET['eid']; 

if($elig_id) { 
    $filename = get_file_name_from_eligibility($elig_id); 
    $file = file_get_contents('./folder/temp/done/'.$filename); 
    print $file; 
} 
?> 
+0

顯示讀取該XML文件的PHP代碼。 –

+0

@JensonMJohn完成。 –

+0

get_file_name_from_eligibility函數定義在哪裏? –

回答

0

與嘗試:

header("content-type: application/xml; charset=ISO-8859-15"); 
0

調用此

header("Content-type: text/xml; charset=utf-8"); 
+0

這不起作用... –

0

這是我要做的事:

<?php 
header("Content-type: text/xml; charset=utf-8"); 
readfile('sitemapindex.xml');