Welcome to WebmasterWorld Guest from

Forum Moderators: httpwebwitch

Message Too Old, No Replies

Error in XML feed

9:51 am on Nov 17, 2008 (gmt 0)

5+ Year Member


Currently I'm creating an "XML-pricefeed" which contains all my actual data that a pricecomparison website can use.

Code of my test XML:


header("Content-type: text/xml");

$host = "localhost";
$user = "#*$!X";
$pass = "#*$!X";
$database = "#*$!X";

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");

$query = "SELECT * FROM product ORDER BY naam ASC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");

$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<entries>\n";

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<entry>\n";
$xml_output .= "\t\t<naam><![CDATA[" . $row['naam'] . "]]></naam>\n";
$xml_output .= "\t\t<content><![CDATA[" . $row['content'] . "]]></content>\n";
$xml_output .= "\t</entry>\n";

$xml_output .= "</entries>";

echo $xml_output;


My output however is all messed up. For instance the output still shows the Cdata tag:

<naam><![CDATA[Name of the product]]></naam>

And like the first 100 rows return empty:

etc etc.

Can anyone assist me in this one?

11:58 am on Nov 17, 2008 (gmt 0)

5+ Year Member

When I now open the page I get this error warnig:

De XML-pagina kan niet worden weergegeven
Kan XML-invoer niet lezen met opmaakmodel XSL. Herstel de fout en klik vervolgens op de knop Vernieuwen of probeer het later opnieuw.


Er is een ongeldig teken gevonden in de tekstinhoud. Fout bij het verwerken van bron http://www.example.com/test/. ...

<content><![CDATA[Some information about this particular product ...

It says so much as that the XML content can not be read and it gives above row as the one where it crashes.

10:34 pm on Nov 17, 2008 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

the CDATA tags are fine - leave them be. it's a real tag and you've got it just as it ought to be.

here are a couple of tips:
1) see if your db has empty rows in it. If it does, use a WHERE clause in the SQL to select only the rows that contain data.

2) I almost always use while instead for, to loop through a data table

while($row = mysql_fetch_array($resultID)){
$output .= "<naam><![CDATA[".$row['naam']."]]></naam>";

you've got a row number where it crashes. Do you see anything unusual about that row?

9:51 am on Nov 18, 2008 (gmt 0)

5+ Year Member

Thanks for your tip. I already changed it into a while statement, but great that you also mentioned! :)

I cant see anything odd about the content of that "content" tag. The only "unuasual" character is a "", but this is used a lot in the content, as are other characters like & ? and so on. Shouldn't the CDATA tags take care of this?

4:06 pm on Nov 18, 2008 (gmt 0)

WebmasterWorld Administrator httpwebwitch is a WebmasterWorld Top Contributor of All Time 10+ Year Member

yes, CDATA is the right way to handle extended characters like "". Still... try using the entity for (is it &eumlaut; ?) and see if that fixes things...

Have you run the XML through a validation parser? find some way to check the XML for well-formedness... sometimes these things are so well camouflaged in the XML they're maddeningly difficult to spot without mechanical assistance.


Featured Threads

Hot Threads This Week

Hot Threads This Month