PHP - Missing tags when exporting database as XML with XMLWriter



I am working with XMLWriter to try and export a database that currently contains about 6700 rows.


From what I have seen, doing this should be relatively straightforward, but during the process of printing the XML, it will not close off an element, therefore creating an error.



$xml = new XMLWriter();

$xml->openURI("php://output");
$xml->startDocument('1.0', 'UTF-8');
$xml->setIndent(true);

$xml->startElement('doc');

while ($row = mysql_fetch_assoc($getResult)) {
$xml->startElement("item");

$xml->startElement("id");
$xml->writeRaw($row['id']);
$xml->endElement();

$xml->startElement("type");
$xml->writeRaw($row['type']);
$xml->endElement();

$xml->startElement("name");
$xml->writeRaw($row['name']);
$xml->endElement();

$xml->endElement();
}

$xml->endElement();

$xml->flush();


At some point during the process, I will see something like this in the XML output:



<type>exampleTypetype>


It will then continue on printing the XML.


I am still relatively new to PHP, so I would appreciate any insight into what could be going on here.


Thanks


No comments:

Post a Comment