仅允许在文档开头的 XML 声明
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14685893/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
XML declaration allowed only at the start of the document
提问by samir panchal
My blog feed show error today:
今天我的博客提要显示错误:
This page contains the following errors:
error on line 2 at column 6: XML declaration allowed only at the start of the document
Below is a rendering of the page up to the first error
此页面包含以下错误:
第 2 行第 6 列错误:仅在文档开头允许 XML 声明
下面是页面渲染到第一个错误
My blog feed: http://feeds.feedburner.com/klassicblog
我的博客提要:http: //feeds.feedburner.com/klassicblog
My blog: http://blog.klassicweb.com
我的博客:http: //blog.klassicweb.com
回答by Asce4s
Here is the solution I found First you create a php file (whitespacefix.php) on the wordpress root dictory with following content.
这是我找到的解决方案 首先,您在 wordpress 根目录上创建一个 php 文件 (whitespacefix.php),内容如下。
<?php
function ___wejns_wp_whitespace_fix($input) {
$allowed = false;
$found = false;
foreach (headers_list() as $header) {
if (preg_match("/^content-type:\s+(text\/|application\/((xhtml|atom|rss)\+xml|xml))/i", $header)) {
$allowed = true;
}
if (preg_match("/^content-type:\s+/i", $header)) {
$found = true;
}
}
if ($allowed || !$found) {
return preg_replace("/\A\s*/m", "", $input);
} else {
return $input;
}
}
ob_start("___wejns_wp_whitespace_fix");
?>
Then open the index.php file and add the following line right after <?phptag
然后打开 index.php 文件并在<?php标签之后添加以下行
include('whitespacefix.php');
Referenced from here
从这里引用
回答by Evert
Your xml document starts with a new-line.
您的 xml 文档以换行符开头。
回答by Anil Gupta
There must be more than 1 blank line at the very end of the functions.php file if you are using wordpress.
如果您使用的是 wordpress,functions.php 文件的最后必须有 1 个以上的空行。
Just remove these blank lines and the error would go off.
只需删除这些空行,错误就会消失。
If you want to know more about the error, read this article: http://www.am22tech.com/fix-xml-declaration-rss-feed-error/
如果您想了解有关错误的更多信息,请阅读这篇文章:http: //www.am22tech.com/fix-xml-declaration-rss-feed-error/
回答by Prince Ahmed
Every page on your page (included sitemaps) contains empty line at the begin. (You can see HTML source) You should remove this line to fix sitemaps. You can try following steps:
您页面上的每个页面(包括站点地图)的开头都包含空行。(您可以查看 HTML 源代码)您应该删除此行以修复站点地图。您可以尝试以下步骤:
Check your wp-config.php file for blank lines outside of bracketed sections.
检查您的 wp-config.php 文件中括号部分之外的空行。
Check your theme's functions.php file for blank lines outside of bracketed sections.
检查您的主题的functions.php 文件中括号部分之外的空行。
One by one, disable plugins and revalidate until you isolate the one causing the problem ( How To Check For Plugin Conflicts )
一个接一个地禁用插件并重新验证,直到找出导致问题的那个(如何检查插件冲突)
Note that the final php ?> should be omitted from all PHP code files - modules, includes, etc. (eg. wp-config.php, functions.php, ...).
请注意,最后的 php ?> 应该从所有 PHP 代码文件中省略 - 模块、包含等(例如 wp-config.php、functions.php 等)。
回答by R Diaz
One of the files included in either your theme, or a plugin, has an empty blank line before the starting
您的主题或插件中包含的文件之一在开始前有一个空行
First, deactivate all plugins, and try to load your sitemap.xml link. If it works now, then one of your plugins is the culprit. If it still does not work, then move on...
首先,停用所有插件,并尝试加载您的 sitemap.xml 链接。如果它现在有效,那么你的插件之一就是罪魁祸首。如果它仍然不起作用,那么继续......
Second, go through each and every one of the .php files that make up your WordPress theme. Find any starting
其次,浏览构成 WordPress 主题的每一个 .php 文件。找到任何开始
Third, reinstall WordPress core installation. If it still doesn't work, then contact a developer to do some deep diving into your source code.
三、重装WordPress核心安装。如果它仍然不起作用,请联系开发人员深入研究您的源代码。

