XML Parsing Error: XML or text declaration not at start of entity in php
Hi I am generating a xml file in php but getting error
XML Parsing Error: XML or text declaration not at start of entity
My code is---
<?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->appendChil开发者_JAVA百科d($dom->createCDATASection($res['description']));
}
echo $test1 = $dom->saveXML();
?>
After search on google i found that it is problem related to space before
I remove space but not getting expected result.
Remove below line and try if the error message has gone Then surely you have space or something else outputted before in the settings.php
file.
header("Content-type:text/xml");
Check settings.php file and remove the spaces if you have. Note that if settings.php file is also including some other files you have to check space in those file also.
Use ob_clean();
before echo $test1 = $dom->saveXML();
精彩评论