XMLwriter在PHP循环中添加Flush

时间:2016-07-08 13:53:32

标签: php xmlwriter

我需要使用PHP循环和xmlwriter创建xml文件。在行动中,我有两个foreach循环:

$writer = new XMLWriter();
$writer->openMemory();
foreach ($nav as $k => $v) {
    $writer->openURI($abspath . '/cache/xmls/news-' . $k . '.xml.gz');
    $writer->startDocument('1.0', 'UTF-8');
    $writer->setIndent(4);
    $writer->startElement('urlset');
    $writer->writeAttribute('xmlns', $xmlns);
    foreach ($v as $k2 => $v2) {
        $writer->startElement('url');
        $writer->writeElement('loc', SITE . '/' . $v2);
        $writer->writeElement('lastmod', '');
        $writer->writeElement('changefreq', '');
        $writer->writeElement('priority', '');
        $writer->endElement();
        $writer->flush();
    }
    $writer->endElement();
    $writer->endDocument();
    $writer->flush();
    $writer->outputMemory();
}

我为每个循环添加Flush();

1-在操作中为每个循环添加flush()是否为TRUE?或者我需要为所有循环添加一个flush(); ?!

2 - 我添加openmemory();这是Fulsh();后的真实?

0 个答案:

没有答案