简体   繁体   English

w3c验证服务是否损坏,或者我迷失了方向?

[英]Is the w3c validation service broken, or am I losing my mind?

I am trying to validate the format of an RSS feed I'm making. 我正在尝试验证我正在制作的RSS feed的格式。 The XML generated looks like this: 生成的XML如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
    <atom:link href="https://foo.bar.net/rss.php" rel="self" type="application/rss+xml" />
    <title>foo.bar Latest News</title>
    <link>https://foo.bar.net/</link>
    <description>Latest news and information of interest at foo.bar</description>
    <pubDate>Thu, 08 Dec 2011 00:08:09 -0500</pubDate>
    <item>
        <title>some title</title>
        <link>https://foo.bar.net/</link>
        <description>some description.</description>
        <pubDate>Wed, 07 Dec 2011 23:04:42 -0500</pubDate>
        <guid>https://foo.bar.net/rss.php?itemId=1</guid>
    </item>
</channel>
</rss>

If I take the text from this page and copy it from here, into the w3c validator at http://validator.w3.org/feed/check.cgi , this validates. 如果我从此页面获取文本并将其从此处复制到位于http://validator.w3.org/feed/check.cgi的w3c验证器中,则将进行验证。 If I take the same text, copied from the browser source, I get the error: 如果我从浏览器源复制了相同的文本,则会收到错误消息:

Sorry

This feed does not validate.
line 2, column 0: XML parsing error: <unknown>:2:0: XML or text declaration not at start of entity [help]

<?xml version="1.0" encoding="UTF-8"?>

If I hit the validate button again (no cutting or pasting this time, just what was already in the text window), I get: 如果我再次点击验证按钮(这次没有剪切或粘贴,只是文本窗口中已经存在的内容),我将得到:

Congratulations!

This is a valid RSS feed.

Say what? 说什么? My RSS reader won't recognize this as a valid feed either, and there seems to be absolutely difference. 我的RSS阅读器也不会将其视为有效的供稿,而且似乎完全不同。 What the heck is going on here? 这里到底发生了什么?

...and yes, I did click on the "help" link. ...是的,我确实点击了“帮助”链接。 It says my feed is not well formed according to the XML specification. 它说我的提要根据XML规范格式不正确。 Having worked in xml for quite a while, I'm not seeing anything jumping out at me. 在xml中工作了一段时间之后,我看不到有什么事情发生。 Could this be some odd encoding issue, and if so, how do I get around it? 这可能是一些奇怪的编码问题,如果是的话,我该如何解决?

It looks to me as if, when you pasted the XML fragment into the validator, you left some whitespace in front of the XML declaration - it's complaining that the XML declaration is on line 2. 在我看来,当您将XML片段粘贴到验证器中时,您在XML声明的前面留了一些空格-这是在抱怨XML声明在第2行。

(Perhaps a nicer design would have been for the validation service to strip any leading whitespace before starting the parse...) (也许对验证服务而言,更好的设计是在开始解析之前剥离所有前导空白...)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM