Is there something else to use instead of header("Content-type: text/xml");
I would like to generate XML out of my database and I keep getting the following error:
Warning: Cannot modify header information - headers already sent by (output started at /Applications/MAMP/htdocs/php32/Eindopdracht/api.php:1) in /Applications/MAMP/htdocs/php32/Eindopdracht/core/functions/api.php on line 41
I already checked of I had any white spaces in it but I don't think that is causing the error. This is the function I wrote in PHP:
function generateXML(){
$sql="SELECT * FROM csvupload";
$result=mysql_query($sql);
$xml = new XMLWriter();
$xml->openURI("php://output");
$xml->startDocument();
$xml->setIndent(true);
$xml->startElement('chords');
while ($row = mysql_fetch_assoc($result)) {
$xml->startElement("chord");
$xml->writeAttribute('E', $row['item1']);
$xml->writeAttribute('a', $row['item2']);
$xml->writeAttribute('d', $row['item3']);
$xml->writeAttribute('g', $row['item4']);
$xml->endElement();
}
$xml->endElement();
header('Content-type: text/xml');
$xml->flush();
}