我正在尝试创建一个简单的 RSS 提要。我使用此服务表单 w3.org验证我的 rss 。这是我的提要的样子:
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>example.com RSS</title>
<link>https://www.example.com/</link>
<description>A cool website</description>
<item>
<title>Cool Article</title>
<link>https://www.example.com/cool-article</link>
<guid>https://www.example.com/cool-article</guid>
<pubDate>Sun, 10 Dec 2017 05:00:00 GMT</pubDate>
<description>My cool article description</description>
</item>
</channel>
</rss>
Run Code Online (Sandbox Code Playgroud)
但我从提要验证器收到此错误:
此提要是有效的,但可以通过实施以下建议来改进与最广泛提要阅读器的互操作性。
第 14 行,第 4 列:缺少 atom:link with rel="self" [帮助]
所以我点击[help]并得到这个:
如果您还没有这样做,请在您的提要顶部声明 Atom 命名空间,因此:
然后在频道部分插入一个 atom:link 到您的提要。下面是一个帮助您入门的示例。请务必将 href 属性的值替换为您的供稿网址。
<atom:link href="http://dallas.example.com/rss.xml" rel="self" type="application/rss+xml" />
好的,首先我试图验证 rss,而不是Atom,但他们似乎试图将我引向 Atom 的方向。好的,我无论如何都会尝试。
<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>example.com RSS</title>
<link>https://www.example.com/</link>
<description>A cool website</description>
<atom:link href="http://www.example.com/rss.xml" rel="self" type="application/rss+xml" />
<item>
<title>Cool Article</title>
<link>https://www.example.com/cool-article</link>
<guid>https://www.example.com/cool-article</guid>
<pubDate>Sun, 10 Dec 2017 05:00:00 GMT</pubDate>
<description>My cool article description</description>
</item>
</channel>
</rss>
Run Code Online (Sandbox Code Playgroud)
验证它,它会给你这个错误:
自我参考与文档位置不匹配 [帮助]
所以我点击[help]并得到这个:
检查 href 属性引用的文档。如果它不是预期的 Feed,请更正它。
这可能不是问题。目前,feedvalidator 不会探测评估文档的等效性。
这就是我被困的地方。他们没有说如何让它做到这一点。我是否可以通过阅读 atom 规范并将我的提要重新实现为 Atom 来做到这一点?因为我不会那样做。
小智 7
您不必将提要从 RSS 转换为 Atom 即可支持atom:link.
要解决此问题,请在atom:link元素中将属性值更改href为 RSS 源的 URL。因此,如果您的 RSS 提要位于http://dallas.example.com/rss.xml,则atom:link 元素应如下所示:
<atom:link href="http://dallas.example.com/rss.xml" rel="self"
type="application/rss+xml" />
Run Code Online (Sandbox Code Playgroud)
在 RSS 源中包含一个atom:link元素可以使其更便携且更易于缓存。有关更多详细信息,请访问RSS 最佳实践简介。