Solved

Coding error assistance needed

Posted on 2009-05-14
10
207 Views
Last Modified: 2012-05-07
Hi all,

I am trying to create an RSS generator but getting the following code error in the code.

This is the error:

XML Parsing Error: XML or text declaration not at start of entity

and the is the code:

echo
'<?xml version="1.0" encoding="ISO-8859-1" ?>

It's pointing here:
<?xml version="1.0" encoding="ISO-8859-1" ?>
^

See arrow above...seems to be the first character?

Hope you can help

thanks

st3vo
0
Comment
Question by:ST3VO
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
10 Comments
 
LVL 3

Accepted Solution

by:
cevoman earned 500 total points
ID: 24389363
Hi there,

if there is anything outputted before this line (even a space or newline) it will throw this error

Kind regards
James
0
 

Author Comment

by:ST3VO
ID: 24389447
When I go to view source it has 3 blank links and then:

<?xml version="1.0" encoding="ISO-8859-1" ?>
<rss version="2.0">
etc...

How do I get rid of lose blank lines...or is that normal?
0
 

Author Comment

by:ST3VO
ID: 24389477
Full error is:

XML Parsing Error: XML or text declaration not at start of entity
Location: http://127.0.0.1/news/rssfeed.php
Line Number 4, Column 1:
<?xml version="1.0" encoding="ISO-8859-1"?>
^

0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Expert Comment

by:cevoman
ID: 24389507
Hi there,

It's those blank lines which are doing it is anything else "Echoing" before that code is run?
Is it part of a template engine or could you provide the full PHP code?

Kind regards
James
0
 

Author Comment

by:ST3VO
ID: 24389586
OK, See code attached
<?php
 include("../includes/dbconn.php");
 
 //the variables
$rss_title= "mysite.com RSS Feed";
 
$rss_site= "mysite.com" ;
 
$rss_description= "Welcome to mysite.com News RSS Feed!";
 
$rss_language="en";
 
$rss_logo="http://www.".$rss_site."/images/rss.jpg";
 
$emailadmin="st3vo@mysite.com"; 
 
header("Content-Type: text/xml;charset=iso-8859-1"); 
 
 
$query = "select * from tbl_news ORDER BY id DESC";
 
$result = mysql_query($query) or die("Query failed"); 
 
?>
 
<?php echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>'.$rss_title.'</title>
<link>http://www.'.$rss_site.'</link>
<description>'.$rss_description.'</description>
<language>en-en</language>
<image>
<url>'.$rss_logo.'</url>
<title>'.$rss_site.'</title>
<link>http://www.'.$rss_site.'</link>
</image>'; 
 
//RSS loop 1
for($i=0;$i<6; $i++)
{
 
//etc....

Open in new window

0
 
LVL 3

Expert Comment

by:cevoman
ID: 24389637
Without knowing what dbconn.php is outputting (if there are any spaces before or after the code in the file)
remove the space from line 25

infact... remove line 24,25 and 26 and check the dbconn.php file

kind regards
James
0
 

Author Comment

by:ST3VO
ID: 24389803
OK it now looks like this:

and the dbconn include is:

<?php
$con = mysql_connect("localhost","root","");
if (!$con)
  {
  die('Could not connect: ' . mysql_error());
  }

mysql_select_db("db2", $con) or
  die('Could not select the database: '.mysql_error());


?>

hope this helps...still got the same error btw

<?php
 include("../includes/dbconn.php");
 
 //the variables
$rss_title= "mysite.com RSS Feed";
 
$rss_site= "mysite.com" ;
 
$rss_description= "Welcome to mysite.com News RSS Feed!";
 
$rss_language="en";
 
$rss_logo="http://www.".$rss_site."/images/rss.jpg";
 
$emailadmin="st3vo@mysite.com"; 
 
header("Content-Type: text/xml;charset=iso-8859-1"); 
 
 
$query = "select * from tbl_news ORDER BY id DESC";
 
$result = mysql_query($query) or die("Query failed"); 
 
echo '<?xml version="1.0" encoding="ISO-8859-1"?>
<rss version="2.0">
<channel>
<title>'.$rss_title.'</title>
<link>http://www.'.$rss_site.'</link>
<description>'.$rss_description.'</description>
<language>en-en</language>
<image>
<url>'.$rss_logo.'</url>
<title>'.$rss_site.'</title>
<link>http://www.'.$rss_site.'</link>
</image>'; 
 
//RSS loop 1
for($i=0;$i<6; $i++)
{
 
//etc....

Open in new window

0
 
LVL 3

Expert Comment

by:cevoman
ID: 24390100
I've just tested the code below seperately and a RSS reader reads it fine, what is producing the error?
	 //the variables
$rss_title= "mysite.com RSS Feed";
 
$rss_site= "mysite.com" ;
 
$rss_description= "Welcome to mysite.com News RSS Feed!";
 
$rss_language="en";
 
$rss_logo="http://www.".$rss_site."/images/rss.jpg";
 
$emailadmin="st3vo@mysite.com"; 
 
header("Content-Type: text/xml;charset=iso-8859-1"); 
 
	echo '<?xml version="1.0" encoding="ISO-8859-1"?>
	<rss version="2.0">
	<channel>
	<title>'.$rss_title.'</title>
	<link>http://www.'.$rss_site.'</link>
	<description>'.$rss_description.'</description>
	<language>en-en</language>
	<image>
	<url>'.$rss_logo.'</url>
	<title>'.$rss_site.'</title>
	<link>http://www.'.$rss_site.'</link>
	</image>';

Open in new window

0
 

Author Comment

by:ST3VO
ID: 24390449
Sorted now...it was the spacing...had to get rid of some closing tags as they appear to create blank space, so all cool here..thanks for your help!

0
 

Author Closing Comment

by:ST3VO
ID: 31581684
cheers :o)
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
EditableGrid how to fetch rows from MySql in php 14 44
MySQL-Design Help 12 40
if statement malfunction 5 18
Get data from two MySQL tables 6 21
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question