XML Parsing Error: xml declaration not at start of external entity

im building my own trackback class for my personal blog.

when i try calling my trackback URL like this: http://localhost/my-blog/this-is-a-test-entry/trackback/  i get the following error:

XML Parsing Error: xml declaration not at start of external entity
Location: http://localhost/my-blog/this-is-a-test-entry/trackback/
Line Number 1, Column 2: <?xml version="1.0" encoding="UTF-8"?>
-^

when i look at the source code, i dont have any whitespaces.  i have checked every line of my code over and over again incase i missed one hiding...

i searched on the web and read that a 8-bit character can be inserted infront of the XML declaration tag but i dont know how it could have?

if i create another example like below it works fine...

<?php
function test()
{
      $xmlWrite = '';
      $xmlWrite .= "<?xml version=\"1.0\" encoding=\"utf-8\" ?>";
      $xmlWrite .= "<test>";
      $xmlWrite .= "<success>works fine...</success>";
      $xmlWrite .= "</test>";
      
      return $xmlWrite;
}

header("Content-type: text/xml");
echo test();
?>

please see my original code below.  I know most of this is PHP so ive included this question in the PHP zone too...
trackback.php - the page that is called when user requests http://domain.com/my-blog/some-blog-entry/trackback/ :
 
<?php
header("Content-type: text/xml");
 
$host = trim($_SERVER['HTTP_HOST']);
 
if(substr($host,0,4) == 'www.')
{	
	$host = substr($host,4);
}
 
$now = date('Y-m-d G:i:s');
$ip = trim($_SERVER['REMOTE_ADDR']);
$agent = trim($_SERVER['HTTP_USER_AGENT']);
$domain = 'http://www.'.trim($host).'/';
 
require_once('classes/class.trackback.php');
 
$trackback = new Trackback('','','UTF-8');
 
global $response, $comment;
 
$tb_id = trim($HTTP_GET_VARS['id']);
$tb_title = trim($HTTP_POST_VARS['title']);
$tb_blog_name = trim($HTTP_POST_VARS['blog_name']);
$tb_url = trim($HTTP_POST_VARS['url']);
$tb_content = substr($HTTP_POST_VARS['excerpt'],0,2000);
$permalink = $domain;
 
if($_SERVER['REQUEST_METHOD'] != 'POST')
{	
	$err_response = 'XML-RPC server accepts POST requests only.';
}
 
// do a few checks to see if trackback is spam or already in table etc etc
 
if($err_response)
{
	echo trim($trackback->recieve(false,$err_response));
}
else
{
	echo trim($trackback->recieve(true,''));
}
?>
 
class.trackback.php recieve function:
 
 function recieve($success = false, $err_response = "") 
 {
        if (!$success && empty($err_response))
		{
            $err_response = "An error occured while tring to log your trackback...";
        }
        
		$return = '<?xml version="1.0" encoding="utf-8"?>'."\n";
        $return .= '<response>'."\n";
        
		if ($success) 
		{
            $return .= '    <error>0</error>'."\n";
        } 
		else 
		{
            $return .= '    <error>1</error>'."\n";
            $return .= '    <message>'.$this->xml_safe($err_response).'</message>'."\n";
        }
		
        $return .= '</response>';
 
        return $return;
    }

Open in new window

LVL 16
ellandrdAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nitinsawhneyCommented:
Hi,

Looks like a header conflict in your code.

Just remove header("Content-type: text/xml"); from your code and it should do the trick.
If it doesn't work then add another "\n" to following line in the function receive
 $return = '<?xml version="1.0" encoding="utf-8"?>'."\n\n";

Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ellandrdAuthor Commented:
ok after removing the header i dont get the above error,but if i view source i still get that whitespace or 8-bit char shown up...
 <?xml version="1.0" encoding="UTF-8"?>
<response>
    <error>1</error>
    <message>You didnt post an id to apply the trackback to...</message>
</response>

Open in new window

0
ellandrdAuthor Commented:
I completely rewrote the whole class and now it works fine this time...

thanks for the time and help

Ellandrd
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
XML

From novice to tech pro — start learning today.