By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,352 Members | 1,645 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,352 IT Pros & Developers. It's quick & easy.

problem in conversion of XML

100+
P: 118
hi,

i run the below code i got the following error and also display output normal way instead of xml entries.plz help that what's the mistake in my code


[php]

<?
header("Content-type: text/xml");
$host = "localhost";
$user = "root";
$pass = "root";
$database = "DataMiningdb";

$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 vehicles ORDER BY vehicle_id DESC";
$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<vehicle_id>" . $row['vehicle_id'] . "</vehicle_id>\n";
// Escaping illegal characters
$row['vehicle_make'] = str_replace("&", "&", $row['vehicle_make']);
$row['vehicle_make'] = str_replace("<", "<", $row['vehicle_make']);
$row['vehicle_make'] = str_replace(">", "&gt;", $row['vehicle_make']);
$row['vehicle_make'] = str_replace("\"", "&quot;", $row['vehicle_make']);
$xml_output .= "\t\t<vehicle_make>" . $row['vehicle_make'] . "</vehicle_make>\n";
$xml_output .= "\t</entry>\n";
}

$xml_output .= "</entries>";
echo $xml_output;

?>
[/php]

output:


Warning: Cannot modify header information - headers already sent by (output started at F:\Facebook\furniture11\Data Mining1\public_html\xmlparsing.php:1) in F:\Facebook\furniture11\Data Mining1\public_html\xmlparsing.php on line 2
5 Bayliner 5 Bayliner 5 Bayliner 4 Bayliner 4 Bayliner 4 Bayliner 3 Baja Marine 3 Baja Marine 3 Baja Marine 2 Miscellaneous 2 Miscellaneous 2 Miscellaneous 1 Miscellaneous 1 Miscellaneous 1 Miscellaneous
Jul 12 '08 #1
Share this Question
Share on Google+
1 Reply


pbmods
Expert 5K+
P: 5,821
Heya, swethak.

Your script is outputting something before the header() call. Check for whitespace/newlines before your opening '<?' tag.
Jul 12 '08 #2

Post your reply

Sign in to post your reply or Sign up for a free account.