I need to add article for each month in xml
file using PHP xmlwriter
:
$sql = \"SELECT *,YEAR(FROM_UNIXTIME(timestamp)) AS YEAR,
You are overwriting your XML with each loop. Consider starting document with root and closing document outside the foreach
loop:
$writer->openURI('./cache/xmls/posts-'.$news['MONTH'].'-'.$news['YEAR'].'.xml');
$writer->startDocument('1.0','UTF-8');
$writer->setIndent(4);
$writer->startElement('urlset');
foreach ($newsdata as $news){
$writer->startElement('url');
$writer->writeElement('loc',$news['title']);
$writer->endElement();
}
$writer->endElement();
$writer->endDocument();
$writer->flush();