3

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->appendChild($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.

2 Answers 2

5

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.

Sign up to request clarification or add additional context in comments.

Comments

4

Use ob_clean(); before echo $test1 = $dom->saveXML();

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.