XML 解析错误:XML 声明格式不正确
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13170843/
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 Parsing Error: XML declaration not well-formed
提问by Fraser
I've created an XML feed which outputs fine in my local dev environment but on the live server, I get the following error:
我创建了一个 XML 提要,它在我的本地开发环境中输出正常,但在实时服务器上,我收到以下错误:
XML Parsing Error: XML declaration not well-formed
Location: http://realaussieadventures.com/home/tourFeed
Line Number 1, Column 15:
<?xml version=1.0 ?>
--------------^
I have tried the version with quotes (<?xml version="1.0" ?>) - works on local - without quotes (<?xml version=1.0 ?>) - doesn't work on local or live - and with escaped quotes () - works on local.
我已经尝试过带引号 ( <?xml version="1.0" ?>)的版本- 在本地工作 - 没有引号 ( <?xml version=1.0 ?>) - 不适用于本地或实时 - 并且带有转义引号 () - 在本地工作。
Local is a MAMP dev environment.
Local 是一个 MAMP 开发环境。
What is wrong with this?
这有什么问题?
回答by shomeax
Thought the answer is a bit outdated, but as question is pretty top at Google, I'll just leave it here.
认为答案有点过时,但由于问题在 Google 上非常重要,我将其留在这里。
Hint: Recheck that your double quotes (") are actual double quotes, e.g. ANSI code 34, not any Unicode double quotation mark (U+201C / U+201D), they may slip into output file by occasion and visually are very hard to track.
提示:重新检查您的双引号 (") 是否是真正的双引号,例如 ANSI 代码 34,而不是任何 Unicode 双引号 (U+201C / U+201D),它们可能会偶尔滑入输出文件中,并且在视觉上很难追踪。
Same goes for single quotes, your favorite Unix editor used to write the script may insert apostrophe/grave accent pair instead of single quotes.
单引号也是如此,您最喜欢的用于编写脚本的 Unix 编辑器可能会插入撇号/重音符号对而不是单引号。
You think this is enough? Nope, I once stumbled upon Unicode non-breakable space character (U+00A0) slipped instead of simple ANSI code 32 space between element attributes. Parser failed miserably.
你觉得这就够了吗?不,我曾经偶然发现 Unicode 不可破坏空格字符 (U+00A0) 滑倒,而不是元素属性之间的简单 ANSI 代码 32 空格。解析器惨遭失败。
Long story short: use strict ANSI editors to prepare XML-generating boilerplate.
长话短说:使用严格的 ANSI 编辑器来准备生成 XML 的样板。
回答by Reagan Ochora
I had the same problem. I realized that I left the version, encoding and the quotes. A well-formed xml has version and encoding.
我有同样的问题。我意识到我离开了版本、编码和引号。格式良好的 xml 具有版本和编码。
<?xml version="1.0" encoding="UTF-8"?>this should be able to work. don't leave out the quotes.
<?xml version="1.0" encoding="UTF-8"?>这应该可以工作。不要遗漏引号。
回答by Lyserty
I had a similar issue, when I tried to open config file in the browser, here is what I had in my case.XML Parsing Error: XML declaration not well-formed
Location: http://localhost:8080/job/MyProject/config.xml
Line Number 1, Column 16:<?xml version='1.1' encoding='UTF-8'?>
---------------^
I tried changing single quotes to double quotes, it didn't help.
But I went I changes XML version from 1.1to 1.0that appears to fix my issue.
我有一个类似的问题,当我尝试在浏览器中打开配置文件时,这就是我的情况。XML Parsing Error: XML declaration not well-formed
Location: http://localhost:8080/job/MyProject/config.xml
Line Number 1, Column 16:<?xml version='1.1' encoding='UTF-8'?>
---------------^
我尝试将单引号更改为双引号,但没有帮助。但是我去我将 XML 版本更改1.1为1.0似乎解决了我的问题。
回答by mark
Try this:
尝试这个:
header("Content-Type: text/xml")
echo " xml version='1.0' encoding='UTF-8' standalone='yes' ";
use single quote in '1.0','UTF-8' etc.. it work for me..
在“1.0”、“UTF-8”等中使用单引号。它对我有用..

