我试图使一个新闻站点地图和站点地图文件打开良好,但在谷歌网站管理员工具测试中,它显示了两个错误:
如有任何帮助,请提前感谢
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;
?>发布于 2018-01-08 09:58:26
在将XML构建为文本时,请确保正确地转义特殊字符。例如,&很有可能成为&的一部分,需要在XML中作为&转义。
更好的解决方案是使用像XMLWriter这样的XML来创建XML。它会照顾好逃跑的人。
https://stackoverflow.com/questions/48138204
复制相似问题