adicione vários dados no arquivo xml usando o PHP xmlwriter

Preciso adicionar artigo para cada mês emxml arquivo usando PHPxmlwriter:

$sql = "SELECT *,YEAR(FROM_UNIXTIME(timestamp)) AS YEAR, 
                MONTH(FROM_UNIXTIME(timestamp)) AS MONTH 
         FROM ".NEWS_ARTICLES." GROUP BY YEAR, MONTH ORDER BY YEAR DESC, MONTH ";
$newsdata = DataAccess::Fetch($sql);

foreach($newsdata AS $news){
    $writer->openURI('./cache/xmls/posts-'.$news['MONTH'].'-'.$news['YEAR'].'.xml');  
    $writer->startDocument('1.0','UTF-8');  
    $writer->setIndent(4);
    $writer->startElement('urlset');
    $writer->writeAttribute('xmlns', $xmlns);
    $writer->startElement('url');   
    $writer->writeElement('loc',$news['title']);  
    $writer->endElement();  
    $writer->endElement(); 
    $writer->endDocument();   
    $writer->flush();
}

Isso funcionou para mim e gerar.xml arquivo para cada mês Mas não adicione o título de todos os artigos para cada mês e só vejoone título em cada arquivo do mês !! como posso adicionar todos os artigos de cada mês em arquivos xml?

Eu acho que meu problema é com loop !!!

resultado:posts-5-2015.xml

<url>
  <loc>title</loc>
</url>

No Really eu tenho 5 artigos e preciso:

resultado:posts-5-2015.xml

<url>
  <loc>title</loc>
</url>
<url>
  <loc>title2</loc>
</url>
<url>
  <loc>title3</loc>
</url>
<url>
  <loc>title4</loc>
</url>
<url>
  <loc>title5</loc>
</url>

print_r($newsdata) resultado: NOTA: isso é simples De banco de dados grande e somente para esquema

Array
(
    [0] => Array
        (
            [id] => 243
            [title] => test2
            [story] => desc2
            [timestamp] => 1442389680
            [update_time] => 1442389522
            [YEAR] => 2015
            [MONTH] => 9
        )

    [1] => Array
        (
            [id] => 242
            [title] => test1
            [story] => desc
            [timestamp] => 1421230680
            [update_time] => 1441026399
            [YEAR] => 2015
            [MONTH] => 1
        )
    [2] => Array
        (
            [id] => 244
            [title] => test3
            [story] => desc3
            [timestamp] => 1421230680
            [update_time] => 1441026399
            [YEAR] => 2015
            [MONTH] => 5
        )
    [3] => Array
        (
            [id] => 245
            [title] => test4
            [story] => desc4
            [timestamp] => 1421230680
            [update_time] => 1441026399
            [YEAR] => 2015
            [MONTH] => 5
        )
    [4] => Array
        (
            [id] => 246
            [title] => test5
            [story] => desc5
            [timestamp] => 1421230680
            [update_time] => 1441026399
            [YEAR] => 2015
            [MONTH] => 5
        )
    [5] => Array
        (
            [id] => 247
            [title] => test6
            [story] => desc6
            [timestamp] => 1421230680
            [update_time] => 1441026399
            [YEAR] => 2015
            [MONTH] => 5
        )
    [6] => Array
        (
            [id] => 248
            [title] => test7
            [story] => desc7
            [timestamp] => 1421230680
            [update_time] => 1441026399
            [YEAR] => 2015
            [MONTH] => 5
        )
)

questionAnswers(2)

yourAnswerToTheQuestion