xml - 动态 XML 站点地图脚本出错
问题描述
我的动态 XML 脚本有问题。我不断收到XML Parsing Error: XML or text declaration not at start of entity错误,并尝试了几乎所有在这里找到的东西,但没有任何效果。有任何想法吗?
编码:
<?php include("connect.php");
$query = "SELECT `website_url` FROM `websites`";
$result = mysqli_query($conn, $query);
$base_url = "http://localhost/test/www.shopperapproved.com/";
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: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;
while($row = mysqli_fetch_array($result)) {
echo '<url>' . PHP_EOL;
echo '<loc>'.$base_url. $row["website_url"] .'/</loc>' . PHP_EOL;
echo '<changefreq>daily</changefreq>' . PHP_EOL;
echo '</url>' . PHP_EOL;
}
echo '</urlset>' . PHP_EOL;
解决方案
我解决了我的问题。刚刚移动了这两行:
header("Content-Type: application/xml; charset=utf-8");
echo '<?xml version="1.0" encoding="UTF-8"?>' . PHP_EOL;
在文件的顶部include("connect.php");
推荐阅读
- r - 识别跨列的特定事件以创建新变量
- sql-server - DTU 已满时 QDS 未显示任何内容
- r - R中的随机图函数
- django - django:无法使用 django 远程身份验证登录
- angular - 普瑞蒙
默认状态和不可编辑 - asp.net-core - 具有 Redis 持久性的 MassTransit 传奇使 Method Accpet 没有实现异常
- angular - 在拦截器中捕获一些错误
- selenium - Selenium:在 XPath 中循环
- c# - 是否可以使用视觉工作室从和向 android firebase 接收和发送数据到 mysql
- ms-access - MS Access 2013 - 让列表框像 excel 切片器一样工作