SyndicationFeed 類別
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
代表頂層的訂閱物件,在 <feed> Atom 1.0 和 <rss> RSS 2.0 中。
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 顯示 a 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> 元素。 |
建構函式
| 名稱 | Description |
|---|---|
| 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 。 |
屬性
| 名稱 | Description |
|---|---|
| AttributeExtensions |
會獲得一組屬性擴充。 |
| Authors |
會獲得訂閱源作者的集合。 |
| BaseUri |
取得或設定該實例的 SyndicationFeed 基礎 URI。 |
| Categories |
會為動態提供一系列分類。 |
| Contributors |
會收到一份貢獻者在動態中的集合。 |
| Copyright |
取得或設定該訂閱源的版權資訊。 |
| Description |
取得或設定動態描述。 |
| Documentation |
取得或設定連結到該訂閱源的文件。 |
| ElementExtensions |
取得 Feed 的元素擴充。 |
| Generator |
接收或設定訊號產生器。 |
| Id |
取得或設定串流的 ID。 |
| ImageUrl |
取得或設定該動態的圖片網址。 |
| Items |
會取得該訂閱中包含的項目集合。 |
| Language |
取得或設定訊號的語言。 |
| LastUpdatedTime |
它會取得或設定串流最後更新的時間。 |
| Links |
會取得與該動態連結的連結。 |
| SkipDays |
會取得一組字串,表示 feed 中 'skipDays' 元素中的值集合。 |
| SkipHours |
會取得一組整數,表示 feed 中 'skipHours' 元素的值集合。 |
| TextInput |
取得或設定 TextInput 屬性來執行訂閱。 |
| TimeToLive |
取得或設定 feed 的 'ttl' 屬性。 |
| Title |
取得或設定串流標題。 |