2011-03-22 67 views
3

嗨,我产生一个PHP的XML文件,但得到错误XML解析错误:XML或文本声明没有在PHP实体开始

XML解析错误:XML或文本声明不在实体的开始

我的代码---

<?php require_once('../../settings.php'); 
header("Content-type:text/xml"); 
$dom=new DOMDocument('1.0'); 
$dom->formatOutput = true; 
$id=(int)$_GET['imageid']; 
$query="select * from tbl_image_gallery where imageId='$id' ORDER BY gallId DESC "; 
$select=mysql_query($query); 
$content = $dom->appendChild($dom->createElement('content')); 
while($res=mysql_fetch_array($select)) 
{ 
    $image = $content->appendChild($dom->createElement('image')); 
    $small_image_path = $image->appendChild($dom->createElement('small_image_path')); 
    $small_image_path->appendChild($dom->createTextNode("image_gallery/load/images/small/".$res['image'])); 
    $big_image_path = $image->appendChild($dom->createElement('big_image_path')); 
    $big_image_path->appendChild($dom->createTextNode("image_gallery/load/images/big/".$res['image'])); 
    $description = $image->appendChild($dom->createElement('description')); 
    $description->appendChild($dom->createCDATASection($res['description'])); 
} 
echo $test1 = $dom->saveXML(); 
?> 

在谷歌搜索后,我发现,这是

我删除空间,但没有得到预期的结果之前,有关空间的问题。

回答

5

删除下面的行,并尝试如果错误消息已经消失然后肯定你有空间或在settings.php文件之前输出的其他东西。

header("Content-type:text/xml"); 

检查settings.php文件并删除空格,如果有的话。请注意,如果settings.php文件也包含一些其他文件,您还必须检查这些文件中的空间。

+0

谢谢。我得到了这个问题。 – rajanikant 2011-03-22 06:31:29

4

使用ob_clean();之前echo $test1 = $dom->saveXML();

+0

这适用于我给1加。 – 2014-02-26 13:29:23