0

我正在开发一个使用 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;
        }
4

0 回答 0