2014-10-06 102 views
0

我是新來的XML,我有以下問題。 我的XML文件是這樣的:使用simplexml_load_file()加載XML文件通過PHP - 文檔末尾的額外內容

<?xml version="1.0" encoding="UTF-8"?> 
<employees> 
    <employee> 

     <Name>John</Name> 
     <Surname>K</Surname> 
     <ID>234</ID> 
     <e-mail>[email protected]</e-mail> 

    </employee> 
</employees> 
</xml> 

我試圖通過PHP加載XML文件:

<?php 

    $filename='../DBfiles/employeesDB.xml'; 
    $xml=simplexml_load_file($filename); 
?> 

和我得到以下幾點:

Warning: simplexml_load_file(): ../DBfiles/employeesDB.xml:12: parser error : Extra content 
at the end of the document in C:\path_to_my_file\www\phpAndAjax\add.php on line 4 

Warning: simplexml_load_file(): &lt;/xml&gt; in C:\path_to_my_file\www\phpAndAjax\add.php on 
line 4 

Warning: simplexml_load_file():^in C:\path_to_my_file\www\phpAndAjax\add.php on line 4 
+0

您還沒有打開''。 – 0x47686F7374 2014-10-06 08:59:33

回答

0

刪除

</xml> 

從文件末尾。沒有開放標籤<xml>,有一個不需要關閉的格式聲明。

+0

它的工作!謝謝! – 2014-10-06 09:08:43

0

您不必關閉文件,只是刪除XML關閉標籤

<?xml version="1.0" encoding="UTF-8"?> 
<employees> 
    <employee> 

    <Name>John</Name> 
    <Surname>K</Surname> 
    <ID>234</ID> 
    <e-mail>[email protected]</e-mail> 

</employee> 
</employees> 
相關問題