SyndicationFeed 类

定义

表示 Atom 1.0 和<feed>RSS 2.0 中的顶级源对象。 <rss>

public ref class SyndicationFeed
[System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)]
public class SyndicationFeed
public class SyndicationFeed
[<System.Diagnostics.CodeAnalysis.DynamicallyAccessedMembers(System.Diagnostics.CodeAnalysis.DynamicallyAccessedMemberTypes.PublicParameterlessConstructor)>]
type SyndicationFeed = class
type SyndicationFeed = class
Public Class SyndicationFeed
继承
SyndicationFeed
属性

示例

以下代码演示如何创建 SyndicationFeed 实例并将其序列化为 Atom 1.0 和 RSS 2.0。

SyndicationFeed feed = new SyndicationFeed("Feed Title", "Feed Description", new Uri("http://Feed/Alternate/Link"), "FeedID", DateTime.Now);
// Add a custom attribute.
XmlQualifiedName xqName = new XmlQualifiedName("CustomAttribute");
feed.AttributeExtensions.Add(xqName, "Value");

SyndicationPerson sp = new SyndicationPerson("jesper@contoso.com", "Jesper Aaberg", "http://Jesper/Aaberg");
feed.Authors.Add(sp);

SyndicationCategory category = new SyndicationCategory("FeedCategory", "CategoryScheme", "CategoryLabel");
feed.Categories.Add(category);

feed.Contributors.Add(new SyndicationPerson("lene@contoso.com", "Lene Aaling", "http://lene/aaling"));
feed.Copyright = new TextSyndicationContent("Copyright 2007");
feed.Description = new TextSyndicationContent("This is a sample feed");

// Add a custom element.
XmlDocument doc = new XmlDocument();
XmlElement feedElement = doc.CreateElement("CustomElement");
feedElement.InnerText = "Some text";
feed.ElementExtensions.Add(feedElement);

feed.Generator = "Sample Code";
feed.Id = "FeedID";
feed.ImageUrl = new Uri("http://server/image.jpg");

TextSyndicationContent textContent = new TextSyndicationContent("Some text content");
SyndicationItem item = new SyndicationItem("Item Title", textContent, new Uri("http://server/items"), "ItemID", DateTime.Now);

List<SyndicationItem> items = new List<SyndicationItem>();
items.Add(item);
feed.Items = items;

feed.Language = "en-us";
feed.LastUpdatedTime = DateTime.Now;

SyndicationLink link = new SyndicationLink(new Uri("http://server/link"), "alternate", "Link Title", "text/html", 1000);
feed.Links.Add(link);

XmlWriter atomWriter = XmlWriter.Create("atom.xml");
Atom10FeedFormatter atomFormatter = new Atom10FeedFormatter(feed);
atomFormatter.WriteTo(atomWriter);
atomWriter.Close();

XmlWriter rssWriter = XmlWriter.Create("rss.xml");
Rss20FeedFormatter rssFormatter = new Rss20FeedFormatter(feed);
rssFormatter.WriteTo(rssWriter);
rssWriter.Close();
Dim feed As SyndicationFeed = New SyndicationFeed("Feed Title", "Feed Description", New Uri("http:'Feed/Alternate/Link"), "FeedID", DateTime.Now)
' Add a custom attribute.
Dim xqName As XmlQualifiedName = New XmlQualifiedName("CustomAttribute")
feed.AttributeExtensions.Add(xqName, "Value")

Dim sp As SyndicationPerson = New SyndicationPerson("jesper@contoso.com", "Jesper Aaberg", "http:'jesper/aaberg")
feed.Authors.Add(sp)

Dim category As SyndicationCategory = New SyndicationCategory("FeedCategory", "CategoryScheme", "CategoryLabel")
feed.Categories.Add(category)

feed.Contributors.Add(New SyndicationPerson("Lene@contoso.com", "Lene Aaling", "http:'Lene/Aaling"))
feed.Copyright = New TextSyndicationContent("Copyright 2007")
feed.Description = New TextSyndicationContent("This is a sample feed")

' Add a custom element.
Dim doc As XmlDocument = New XmlDocument()
Dim feedElement As XmlElement = doc.CreateElement("CustomElement")
feedElement.InnerText = "Some text"
feed.ElementExtensions.Add(feedElement)

feed.Generator = "Sample Code"
feed.Id = "FeedID"
feed.ImageUrl = New Uri("http:'server/image.jpg")

Dim textContent As TextSyndicationContent = New TextSyndicationContent("Some text content")
Dim item As SyndicationItem = New SyndicationItem("Item Title", textContent, New Uri("http:'server/items"), "ItemID", DateTime.Now)

Dim items As Collection(Of SyndicationItem) = New Collection(Of SyndicationItem)()
items.Add(item)
feed.Items = items

feed.Language = "en-us"
feed.LastUpdatedTime = DateTime.Now

Dim link As SyndicationLink = New SyndicationLink(New Uri("http:'server/link"), "alternate", "Link Title", "text/html", 1000)
feed.Links.Add(link)

Dim atomWriter As XmlWriter = XmlWriter.Create("atom.xml")
Dim atomFormatter As Atom10FeedFormatter = New Atom10FeedFormatter(feed)
atomFormatter.WriteTo(atomWriter)
atomWriter.Close()

Dim rssWriter As XmlWriter = XmlWriter.Create("rss.xml")
Dim rssFormatter As Rss20FeedFormatter = New Rss20FeedFormatter(feed)
rssFormatter.WriteTo(rssWriter)
rssWriter.Close()

以下 XML 演示如何将 SyndicationFeed 序列化为 Atom 1.0。

<feed xml:lang="en-us" CustomAttribute="Value" xmlns="http://www.w3.org/2005/Atom">
  <title type="text">Feed Title</title>
  <subtitle type="text">This is a sample feed</subtitle>
  <id>FeedID</id>

  <rights type="text">Copyright 2007</rights>
  <updated>2007-04-13T17:29:38Z</updated>
  <category term="FeedCategory" label="CategoryLabel" scheme="CategoryScheme" />
  <logo>http://contoso/image.jpg</logo>
  <author>
    <name>Jesper Aaberg</name>
    <uri>http://contoso/Aaberg</uri>
    <email>Jesper.Asberg@contoso.com</email>
  </author>
  <contributor>
    <name>Lene Aalling</name>
    <uri>http://contoso/Aalling</uri>
    <email>Lene.Aaling@contoso.com</email>
  </contributor>
  <generator>Sample Code</generator>
  <link rel="alternate" type="text/html" title="Link Title" length="1000" href="http://contoso/link" />

  <link customAttribute="value" rel="alternate" type="text/html" title="Link Title" length="1000" href="http://contoso/link" />
  <CustomElement xmlns="">Some text</CustomElement>
  <entry>
    <id>ItemID</id>
    <title type="text">Item Title</title>
    <updated>2007-04-13T17:29:38Z</updated>
    <link rel="alternate" href="http://contoso/items" />
    <content type="text">Some text content</content>
  </entry>

</feed>

以下 XML 演示如何 SyndicationFeed 将实例序列化为 RSS 2.0。

<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">
  <channel CustomAttribute="Value">
    <title>Feed Title</title>
    <link>http://feed/Alternate/Link</link>
    <description>This is a sample feed</description>
    <language>en-us</language>

    <copyright>Copyright 2007</copyright>

    <managingEditor>Jesper.Aaberg@contoso.com</managingEditor>
    <lastBuildDate>Fri, 13 Apr 2007 17:29:38 Z</lastBuildDate>
    <category domain="CategoryScheme">FeedCategory</category>
    <a10:link rel="alternate" type="text/html" title="Link Title" length="1000" href="http://contoso/link" />
    <generator>Sample Code</generator>
    
    <a10:contributor>
      <a10:name>Lene Aalling</a10:name>
      <a10:uri>http://contoso/Aalling</a10:uri>
      <a10:email>Lene.Aalling@contoso.com</a10:email>
    </a10:contributor>
    
    <a10:author>
      <a10:name>Lene Aalling</a10:name>
      <a10:uri>http://contoso/Aalling</a10:uri>
      <a10:email>Lene.Aalling@contoso.com</a10:email>
    </a10:author>
    <image>
      <url>http://contoso/image.jpg</url>
      <title>Feed Title</title>
      <link>http://feed/Alternate/Link</link>
    </image>
    <a10:id>FeedID</a10:id>
    <a10:link customAttribute="value" rel="alternate" type="text/html" title="Link Title" length="1000" href="http://contoso/link" />
    
    <CustomElement>Some text</CustomElement>
    <item>
      <guid isPermaLink="false">ItemID</guid>
      <link>http://contoso/items</link>
      <title>Item Title</title>
      <description>Some text content</description>
      <a10:updated>2007-04-13T17:29:38Z</a10:updated>
    </item>
  </channel>
</rss>

注解

序列化为 Atom 1.0 时, SyndicationFeed 实例将写入 <feed> 元素。 下表显示了类中 SyndicationFeed 定义的每个属性如何序列化为 Atom 1.0。

SyndicationFeed 属性 序列化窗体
AttributeExtensions 集合中每个属性的 <feed> 元素中的属性。
Authors <author>集合中每个SyndicationPerson元素的元素。
Categories <category>集合中每个SyndicationCategory元素的元素。
Contributors <contributor>集合中每个SyndicationPerson元素的元素。
Copyright 元素 <rights>
Description 元素 <subtitle>
ElementExtensions 集合中的每个元素都写入元素 <feed> 中。
Generator 元素 <generator>
Id <id> 元素。
ImageUri 元素 <logo>
Items <entry>集合中每个SyndicationItem元素的元素。
Language 未序列化。
LastUpdatedTime <updated> 元素。
Links <link>集合中每个SyndicationLink元素的元素。
Title 元素 <title>

序列化为 RSS 2.0 时, SyndicationFeed 实例将 <rss> 写入元素。 下表显示了类中 SyndicationFeed 定义的每个属性如何序列化为 RSS 2.0。

SyndicationFeed 属性 序列化窗体
AttributeExtensions 集合中每个属性的 <channel> 元素中的属性。
Authors <managingEditor>如果集合中只有一SyndicationPerson个元素,则为一个<a10:author>元素;否则为集合中的每个元素SyndicationPerson
Categories <category>集合中每个SyndicationCategory元素的元素。
Contributors <a10:contributor>集合中每个SyndicationPerson元素的元素。
Copyright 元素 <copyright>
Description 元素 <description>
ElementExtensions 集合中的每个元素都写入元素 <channel> 中。
Generator 元素 <generator>
Id <a10:id> 元素。
ImageUri <image> 元素。
Items <item>集合中每个SyndicationItem元素的元素。
Language 元素 <language>
LastUpdatedTime 元素 <lastBuildDate>
Links <a10:link>集合中每个SyndicationLink元素的元素。
Title 元素 <title>

构造函数

名称 说明
SyndicationFeed()

初始化 SyndicationFeed 类的新实例。

SyndicationFeed(IEnumerable<SyndicationItem>)

使用指定的对象集合SyndicationFeed初始化类的新实例SyndicationItem

SyndicationFeed(String, String, Uri, IEnumerable<SyndicationItem>)

使用指定的标题、说明、URI 和对象的集合SyndicationFeed初始化类的新实例SyndicationItem

SyndicationFeed(String, String, Uri, String, DateTimeOffset, IEnumerable<SyndicationItem>)

创建类的新实例 SyndicationFeed

SyndicationFeed(String, String, Uri, String, DateTimeOffset)

创建类的新实例 SyndicationFeed

SyndicationFeed(String, String, Uri)

使用指定的标题、说明和统一资源标识符(URI)初始化类的新实例 SyndicationFeed

SyndicationFeed(SyndicationFeed, Boolean)

使用指定的源创建类的新实例 SyndicationFeed

属性

名称 说明
AttributeExtensions

获取属性扩展的集合。

Authors

获取源的作者集合。

BaseUri

获取或设置实例的 SyndicationFeed 基 URI。

Categories

获取源的类别集合。

Contributors

获取源参与者的集合。

Copyright

获取或设置源的版权信息。

Description

获取或设置源的说明。

Documentation

获取或设置源的文档链接。

ElementExtensions

获取源的元素扩展。

Generator

获取或设置源的生成器。

Id

获取或设置源的 ID。

ImageUrl

获取或设置源的图像 URL。

Items

获取源中包含的源项的集合。

Language

获取或设置源的语言。

LastUpdatedTime

获取或设置上次更新源的时间。

Links

获取与源关联的链接。

SkipDays

获取字符串的集合,该集合指示源的“skipDays”元素中的值集。

SkipHours

获取整数集合,该集合指示源的“skipHours”元素中的值集。

TextInput

获取或设置源的 TextInput 属性。

TimeToLive

获取或设置源的“ttl”属性。

Title

获取或设置源的标题。

方法

名称 说明
Clone(Boolean)

创建实例的副本 SyndicationFeed

CreateCategory()

创建新的 SyndicationCategory 实例。

CreateItem()

创建新的 SyndicationItem 实例。

CreateLink()

创建新的 SyndicationLink 实例。

CreatePerson()

创建新的 SyndicationPerson 实例。

Equals(Object)

确定指定的对象是否等于当前对象。

(继承自 Object)
GetAtom10Formatter()

获取实例 Atom10FeedFormatter

GetHashCode()

用作默认哈希函数。

(继承自 Object)
GetRss20Formatter()

获取实例 Rss20FeedFormatter

GetRss20Formatter(Boolean)

获取新 Rss20FeedFormatter 实例。

GetType()

获取当前实例的 Type

(继承自 Object)
Load(XmlReader)

从指定的 XML 读取器加载联合源。

Load<TSyndicationFeed>(XmlReader)

SyndicationFeed从指定的XmlReader实例加载派生实例。

MemberwiseClone()

创建当前 Object的浅表副本。

(继承自 Object)
SaveAsAtom10(XmlWriter)

将联合源写入 Atom 1.0 格式中指定的 XmlWriter 源。

SaveAsRss20(XmlWriter)

将联合源写入 RSS 2.0 格式指定的 XmlWriter 源。

ToString()

返回一个表示当前对象的字符串。

(继承自 Object)
TryParseAttribute(String, String, String, String)

尝试分析属性扩展。

TryParseElement(XmlReader, String)

尝试分析元素扩展。

WriteAttributeExtensions(XmlWriter, String)

使用指定的联合版本将属性扩展写入指定的 XmlWriter 属性扩展。

WriteElementExtensions(XmlWriter, String)

使用指定的联合版本将元素扩展写入指定的 XmlWriter

适用于