SyndicationFeed 類別

定義

代表頂層摘要物件:Atom 1.0 中的 <feed> 和 RSS 2.0 中的 <rss>。

public ref class SyndicationFeed
public class SyndicationFeed
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)

以指定的標題、描述以及統一資源識別元 (URI) 初始化 SyndicationFeed 類別的新執行個體。

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

以指定的標題、描述、URI 及 SyndicationFeed 物件的集合,初始化 SyndicationItem 類別的新執行個體。

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

建立 SyndicationFeed 類別的新執行個體。

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

建立 SyndicationFeed 類別的新執行個體。

SyndicationFeed(SyndicationFeed, Boolean)

使用指定的摘要來建立 SyndicationFeed 類別的新執行個體。

屬性

AttributeExtensions

取得屬性擴充的集合。

Authors

取得摘要作者的集合。

BaseUri

取得或設定 SyndicationFeed 執行個體的基底 URI。

Categories

取得摘要分類的集合。

Contributors

為摘要取得參與者的集合。

Copyright

取得或設定摘要的著作權資訊。

Description

取得或設定摘要的描述。

Documentation

取得或設定摘要文件的連結。

ElementExtensions

為摘要取得項目延伸。

Generator

取得或設定摘要的產生器。

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)

自指定的 XmlReader 載入 SyndicationFeed 衍生執行個體。

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

適用於