i keep getting a xml parse error, and i think its gotta do with spaces and comments, but since i'm kinda new to php, mysql and xml i'm not 100% sure if the following code is correct.
I am getting the error:
XML-parsefout: troep na documentelement
Locatie: xml.php
Regelnummer 10, kolom 1:<project id="90">
^
Translated:
XML-parseerror: junk after document element
Location: xml.php
Regelnummer 10, kolom 1:<project id="90">
^
Code:
<?php
$sql = "SELECT * FROM projecten ORDER BY id";
$res = mysql_query($sql);
$version = '1.0';
$encoding = 'UTF-8';
$xml = new XMLWriter();
$xml->openURI("php://output");
$xml->startDocument();
$xml->setIndent(true);
//WHILE LOOP OM ALLE GEGEVENS UIT DE QUERY TE HALEN
while ($row = mysql_fetch_assoc($res)) {
//START PROJECT
$xml->startElement('project');
$xml->writeAttribute('id', $row['id']);
//ID
$xml->startElement("id");
$xml->writeRaw($row['id']);
$xml->endElement();
//PROJECTNAAM
$xml->startElement("projectnaam");
$xml->writeRaw($row['projectnaam']);
$xml->endElement();
//PROJECTSTATUS
$xml->startElement("status");
$xml->writeRaw($row['status']);
$xml->endElement();
//KLANTNAAM
$xml->startElement("klantnaam");
$xml->writeRaw($row['klantnaam']);
$xml->endElement();
//STARTDATUM
$xml->startElement("startdatum");
$xml->writeRaw($row['startdatum']);
$xml->endElement();
//EINDDATUM
$xml->startElement("eindddatum");
$xml->writeRaw($row['einddatum']);
$xml->endElement();
//EINDE PROJECT
$xml->endElement();
}
//EINDE DOCUMENT
$xml->endDocument();
header('Content-type: text/xml');
$xml->flush();
?>
This is what the browser generates:
<parsererror>
XML-parsefout: troep na documentelement Locatie: xml.php Regelnummer 10, kolom 1:
<sourcetext><project id="90"> ^</sourcetext>
</parsererror>