After executing the code below (minus the database call), I am receiving a "error on line 331 at column 7: Extra content at the end of the document" error. I went through these forums, but could not find a solution. I don't have any random characters or any code that should be adding that extra whitespace... Any ideas?
<?php
header('Content-type: text/xml');
mysql_connect("localhost", "---", "---");
mysql_select_db("---");
$query = "SELECT title FROM table";
$result = mysql_query($query);
$xml = new XMLWriter();
$xml->openURI("php://output");
$xml->startDocument();
$xml->setIndent(true);
$xml->writeRaw('<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9">');
$xml->startElement('url');
while ($row = mysql_fetch_assoc($result)) {
if(!empty($row)){
$title = $row['title'];
$xml->startElement('loc');
$xml->writeRaw('http://domain.com/article/');
$xml->endElement();
$xml->startElement('news:news');
$xml->startElement("news:publication");
$xml->startElement("news:name");
$xml->writeRaw('Name');
$xml->endElement();
$xml->startElement("news:language");
$xml->writeRaw('en');
$xml->endElement();
$xml->endElement();
$xml->startElement('news:title');
$xml->writeRaw($title);
$xml->endElement();
$xml->endElement();
}
}
$xml->endElement();
$xml->flush();