Forum Moderators: open
Currently I'm creating an "XML-pricefeed" which contains all my actual data that a pricecomparison website can use.
Code of my test XML:
<?php
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:
<entry>
<naam><![CDATA[]]></naam>
<content><![CDATA[]]></content>
</entry>
<entry>
<naam><![CDATA[]]></naam>
<content><![CDATA[]]></content>
</entry>
<entry>
<naam><![CDATA[]]></naam>
<content><![CDATA[]]></content>
</entry>
<entry>
<naam><![CDATA[]]></naam>
<content><![CDATA[]]></content>
</entry>
<entry>
etc etc.
Can anyone assist me in this one?
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.
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?
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?
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.