【发布时间】:2018-06-16 17:14:08
【问题描述】:
我正在尝试制作新闻站点地图,并且站点地图文件可以正常打开,但在 google 网站管理员工具测试中显示两个错误:
- 无效的 XML 标记
- 预期:您的站点地图或站点地图索引文件未正确声明命名空间。您的站点地图或站点地图索引文件未正确声明命名空间。预期:http://www.w3.org/1999/xhtml 发现:http://www.sitemaps.org/schemas/sitemap/0.9
任何帮助提前谢谢
header("Content-Type: application/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>'.PHP_EOL;
echo '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xlink="http://www.w3.org/1999/xlink" 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">' . PHP_EOL;
$base_url = "https://www.example.com";
while($row = mysqli_fetch_array($sitegrab))
{
echo '<url>' . PHP_EOL;
echo '<loc>'.$base_url.'</loc>' . PHP_EOL;
echo '<news:name>'.$row['Website'].'</news:name>' . PHP_EOL;
echo '<news:link>'.$row['Link'].'</news:link>' . PHP_EOL;
echo '<changefreq>daily</changefreq>' . PHP_EOL;
echo '<priority>1</priority>' . PHP_EOL;
echo '</url>' . PHP_EOL;
}
echo '</urlset>' . PHP_EOL;
?>
【问题讨论】:
标签: php xml sitemap google-search-console