SyndicationPerson没有正确转换为RSS

时间:2016-05-04 07:39:53

标签: c# syndication syndication-feed

我正在使用SyndicationItem将文章转换为RSS的网站上工作。 我的问题是作者(SyndicationPerson)只显示电子邮件地址(如果存在),否则名称仅如下所示: 如果存在电子邮件:

<author>name@email.com</author>

如果缺少电子邮件:

<author>
  <name>First Name Last Name</name>
</author>

应该显示两者:

<author>
   <name></name>
   <email></email>
</author>

那么是什么控制了这个或者是否存在缺失的东西?

重要的部分代码:

var syndicationItem = new SyndicationItem(GetItemTitle(article), GetItemSummary(article), new Uri(articleUrl), article.AbsoluteUrl, article.Date);
syndicationItem = AddAuthorsToFeedItem(syndicationItem, article);
syndicationItems.Add(syndicationItem);
feed.Items = syndicationItems;

var output = new StringBuilder();

using (var writer = XmlWriter.Create(output, new XmlWriterSettings {Indent = true}))
{
    feed.SaveAsRss20(writer);
    writer.Flush();
    writer.Close();
    return output.ToString();
}




private SyndicationItem AddAuthorsToFeedItem(SyndicationItem syndicationItem, Article article)
        {
            foreach (var author in article.Authors)
            {
                var authorName = author.First_Name + " " + author.Last_Name;
                var person = new SyndicationPerson(author.Email_Address, authorName, string.Empty);
                syndicationItem.Authors.Add(person);
            }
            return syndicationItem;
        }

0 个答案:

没有答案