我使用SyndicationFeed
生成Atom Feed。
除非我使用W3C Feed Validation Service验证我的Feed,否则我似乎已全部工作了,我收到以下警告。
此Feed有效,但可以通过实施以下建议来改进与最广泛的Feed阅读器的互操作性。 第2行,第0列:缺少原子:与rel ="自我"
的链接
向我创建的代码添加属性非常简单,但如何让SyndicationFeed
添加呢?我没有看到这个设置。
这是我的Feed的第一部分。
<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en-us">
<title type="text">Insider Articles</title>
<subtitle type="text">Insider Articles data feed.</subtitle>
<id>http://www.insiderarticles.com/Syndication/Atom</id>
<rights type="text">Copyright (c) 2016 Insider Articles. All Rights Reserved.</rights>
<updated>2016-10-02T12:47:21-07:00</updated>
<logo>http://www.insiderarticles.com/Content/Images/rss.jpg</logo>
<link rel="alternate" href="http://www.insiderarticles.com/" />
<entry>
<!-- Etc... -->
以下是我如何构建Feed(减去Feed项)。
// Construct feed
SyndicationFeed feed = new SyndicationFeed(
Properties.Settings.Default.ApplicationName,
Properties.Settings.Default.FeedSummary,
new Uri(Properties.Settings.Default.ApplicationDomainRoot),
string.Format("{0}/Syndication/Atom", Properties.Settings.Default.ApplicationDomainRoot),
DateTime.Now);
feed.Language = "en-us";
feed.Copyright = new TextSyndicationContent(Properties.Settings.Default.ApplicationCopyright);
feed.ImageUrl = new Uri(string.Format("{0}/Content/Images/rss.jpg", uriRoot));
feed.Items = items;
答案 0 :(得分:0)
虽然上面的代码添加了备用链接(rel="alternate"
),但验证者也想要一个指向原始Feed的链接(rel="self"
)。
因此,添加以下代码可以解决问题。
string feedUrl = string.Format("{0}/Syndication/Atom", UrlBuilder.GetUriRoot(uri));
// Add feed (self) URL
var link = new SyndicationLink(new Uri(feedUrl));
link.RelationshipType = "self";
feed.Links.Add(link);