您好,我正在用 php 生成一个 xml 文件,但出现错误
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();
?>
google了一下发现是之前空格的问题
我删除了空格但没有得到预期的结果。
最佳答案
删除下面的行并尝试错误消息是否消失然后肯定你在 settings.php
文件中有空间或其他输出。
header("Content-type:text/xml");
检查 settings.php 文件并删除空格(如果有)。请注意,如果 settings.php 文件还包含一些其他文件,您还必须检查这些文件中的空间。
关于php - XML 解析错误 : XML or text declaration not at start of entity in php,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5387514/