假设我有文本数据库包括:
http://example.com,monthly,0.3
http://example.com/one,daily,0.5
http://example.com/two,weekly,0,8
我想将我的文本数据库转换为 sitemap.xml。
$fp = fopen('./database.txt', 'r');
$xml = new XMLWriter;
$xml->openURI('./sitemap.xml');
$xml->setIndent(true);
$xml->startElement('urlset');
while ($line = fgetcsv($fp)) {
if (count($line) < 4) continue;
$xml->startElement('url');
$xml->writeElement('loc', $line[0]);
$xml->writeElement('changefreq', $line[1]);
$xml->writeElement('priority', $line[2]);
echo $xliff->getDocument();
$xml->endElement();
}
$xml->endElement();
我试过这段代码,我无法添加这部分......
<?xml version="1.0" encoding="UTF-8"?>
<urlset
xmlns='http://www.sitemaps.org/schemas/sitemap/0.9'
xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'
xsi:schemaLocation='http://www.sitemaps.org/schemas/sitemap/0.9 http://www.sitemaps.org/schemas/sitemap/0.9/sitemap.xsd">