我使用SyndicationFeed生成一个Atom。
除了使用W3C饲料验证服务验证我的提要之外,我似乎所有东西都能正常工作,我收到以下警告。
这个提要是有效的,但是通过实现以下建议,可以提高与最广泛的提要阅读器的互操作性。第2行,第0列:缺少原子:与rel="self“链接
向我创建的标记添加属性很容易,但是如何让SyndicationFeed添加属性呢?我没看到这样的背景。
这是我饲料的第一部分。
<?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... -->下面是构建提要的方法(减去提要项)。
// 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;发布于 2016-10-02 20:29:40
虽然我上面的代码添加了一个备用链接(rel="alternate"),但是验证器也需要一个指向原始提要的链接(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);https://stackoverflow.com/questions/39821046
复制相似问题