2014-10-06 107 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> 
相关问题