请单击以进行评分并提供反馈

  开启低带宽视图
.NET Framework 类库
SyndicationFeed 类

更新:2007 年 11 月

表示顶级源对象:Atom 1.0 中为 <feed>,而 RSS 2.0 中为 <rss>。

命名空间:  System.ServiceModel.Syndication
程序集:  System.ServiceModel.Web(在 System.ServiceModel.Web.dll 中)
Visual Basic(声明)
Public Class SyndicationFeed
Visual Basic (用法)
Dim instance As SyndicationFeed
C#
public class SyndicationFeed
Visual C++
public ref class SyndicationFeed
J#
public class SyndicationFeed
JScript
public class SyndicationFeed

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

SyndicationFeed 属性

序列化形式

AttributeExtensions

集合中每个属性的 <feed> 元素中的属性。

Authors

集合中每个 SyndicationPerson 的 <author> 元素。

Categories

集合中每个 SyndicationCategory 的 <category> 元素。

Contributors

集合中每个 SyndicationPerson 的 <contributor> 元素。

Copyright

<rights> 元素。

Description

<subtitle> 元素。

ElementExtensions

集合中的每个元素都会写入 <feed> 元素中。

Generator

<generator> 元素。

Id

<id> 元素。

ImageUri

<logo> 元素。

Items

集合中每个 SyndicationItem 的 <entry> 元素。

Language

未序列化。

LastUpdatedTime

<updated> 元素。

Links

集合中每个 SyndicationLink 的 <link> 元素。

Title

<title> 元素。

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

SyndicationFeed 属性

序列化形式

AttributeExtensions

集合中每个属性的 <channel> 元素中的属性。

Authors

如果集合中只有一个 SyndicationPerson,则为 <managingEditor> 元素;否则为集合中每个 SyndicationPerson 的 <a10:author> 元素。

Categories

集合中每个 SyndicationCategory 的 <category> 元素。

Contributors

集合中每个 SyndicationPerson 的 <a10:contributor> 元素。

Copyright

<copyright> 元素。

Description

<description> 元素。

ElementExtensions

集合中的每个元素都会写入 <channel> 元素中。

Generator

<generator> 元素。

Id

<a10:id> 元素。

ImageUri

<image> 元素。

Items

集合中每个 SyndicationItem 的 <item> 元素。

Language

<language> 元素。

LastUpdatedTime

<lastBuildDate> 元素。

Links

集合中每个 SyndicationLink 的 <a10:link> 元素。

Title

<title> 元素。

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

C#
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();


下面的 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>

System..::.Object
  System.ServiceModel.Syndication..::.SyndicationFeed
此类型的任何公共 static(在 Visual Basic 中为 Shared) 成员都是线程安全的。但不保证所有实例成员都是线程安全的。

Windows Vista, Windows XP SP2, Windows Server 2003

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

.NET Framework

受以下版本支持:3.5
社区内容   什么是社区内容?
添加新内容 RSS  批注
Processing
© 2009 Microsoft Corporation 版权所有。 保留所有权利  |  商标  |  隐私权声明
Page view tracker