Wie das WCF-Syndication-Objektmodell Atom und RSS zugeordnet wirdHow the WCF Syndication Object Model Maps to Atom and RSS

Wenn Sie einen Windows Communication Foundation (WCF)-Syndication-Dienst zu entwickeln, erstellen Sie Feeds und Elemente, die mit den folgenden Klassen:When developing a Windows Communication Foundation (WCF) syndication service, you create feeds and items using the following classes:

Ein SyndicationFeed kann in jedes beliebige Syndication-Format serialisiert werden, für das ein Formatierungsprogramm definiert ist.A SyndicationFeed can be serialized into any syndication format for which a formatter is defined. WCF wird mit zwei Formatierungsprogrammen geliefert: Atom10FeedFormatter und Rss20FeedFormatter.WCF ships with two formatters: Atom10FeedFormatter and Rss20FeedFormatter.

Das Objektmodell um SyndicationFeed und SyndicationItem orientiert sich näher an der Atom 1.0-Spezifikation als der RSS 2.0-Spezifikation.The object model around SyndicationFeed and SyndicationItem is aligned more closely with the Atom 1.0 specification than the RSS 2.0 specification. Das liegt daran, dass Atom 1.0 eine umfassendere Spezifikation ist, die Elemente definiert, die in der RSS 2.0-Spezifikation nicht eindeutig sind oder fehlen.This is because Atom 1.0 is a more substantial specification that defines elements that are ambiguous or omitted from the RSS 2.0 specification. Aus diesem Grund haben viele Elemente im WCF Syndication-Objektmodell keine direkte Darstellung in der Spezifikation RSS 2.0.Because of this, many items in the WCF syndication object model have no direct representation in the RSS 2.0 specification. Bei der Serialisierung SyndicationFeed und SyndicationItem -Objekten in RSS 2.0 WCF ermöglicht es Ihnen, Atom-spezifische Datenelemente als Namespace gekennzeichnete Erweiterungselemente zu serialisieren, die der Atom-Spezifikation entsprechen.When serializing SyndicationFeed and SyndicationItem objects into RSS 2.0, WCF allows you to serialize Atom-specific data elements as namespace-qualified extension elements that conform to the Atom specification. Sie können diesen Vorgang anhand eines Parameters steuern, der an den Rss20FeedFormatter-Konstruktor übergeben wird.You can control this with a parameter passed to the Rss20FeedFormatter constructor.

Für die Codebeispiele in diesem Thema wird eine der beiden hier definierten Methoden für die Serialisierung verwendet.The code samples in this topic use one of two methods defined here to do the actual serialization.

SerializeFeed serialisiert einen Syndication-Feed.SerializeFeed serializes a syndication feed.

public void SerializeFeed(SyndicationFeed feed)
{
    Atom10FeedFormatter atomFormatter = feed.GetAtom10Formatter();
    Rss20FeedFormatter rssFormatter = feed.GetRss20Formatter();

    XmlWriter atomWriter = XmlWriter.Create("atom.xml");
    XmlWriter rssWriter = XmlWriter.Create("rss.xml");
    atomFormatter.WriteTo(atomWriter);
    rssFormatter.WriteTo(rssWriter);
    atomWriter.Close();
    rssWriter.Close();
}
Public Sub SerializeFeed(ByVal feed As SyndicationFeed)

    Dim atomFormatter As Atom10FeedFormatter = feed.GetAtom10Formatter()
    Dim rssFormatter As Rss20FeedFormatter = feed.GetRss20Formatter()

    Dim atomWriter As XmlWriter = XmlWriter.Create("atom.xml")
    Dim rssWriter As XmlWriter = XmlWriter.Create("rss.xml")
    atomFormatter.WriteTo(atomWriter)
    rssFormatter.WriteTo(rssWriter)
    atomWriter.Close()
    rssWriter.Close()
End Sub

SerializeItem serialisiert ein Syndication-Element.SerializeItem serializes a syndication item.

public void SerializeItem(SyndicationItem item)
{
    Atom10ItemFormatter atomFormatter = item.GetAtom10Formatter();
    Rss20ItemFormatter rssFormatter = item.GetRss20Formatter();

    XmlWriter atomWriter = XmlWriter.Create("atom.xml");
    XmlWriter rssWriter = XmlWriter.Create("rss.xml");
    atomFormatter.WriteTo(atomWriter);
    rssFormatter.WriteTo(rssWriter);
    atomWriter.Close();
    rssWriter.Close();
}
Public Sub SerializeItem(ByVal item As SyndicationItem)
    Dim atomFormatter As Atom10ItemFormatter = item.GetAtom10Formatter()
    Dim rssFormatter As Rss20ItemFormatter = item.GetRss20Formatter()

    Dim atomWriter As XmlWriter = XmlWriter.Create("atom.xml")
    Dim rssWriter As XmlWriter = XmlWriter.Create("rss.xml")
    atomFormatter.WriteTo(atomWriter)
    rssFormatter.WriteTo(rssWriter)
    atomWriter.Close()
    rssWriter.Close()
End Sub

SyndicationFeedSyndicationFeed

Das folgende Codebeispiel zeigt, wie die SyndicationFeed-Klasse in Atom 1.0 und RSS 2.0 serialisiert wird.The following code example shows how to serialize the SyndicationFeed class to Atom 1.0 and RSS 2.0.

SyndicationFeed feed = new SyndicationFeed("My Feed Title", "My Feed Description", new Uri("http://MyFeedURI"));
feed.Copyright = new TextSyndicationContent("Copyright 2007");
feed.Language = "EN-US";
feed.LastUpdatedTime = DateTime.Now;
feed.Generator = "Sample Code";
feed.Id = "FeedID";
feed.ImageUrl = new Uri("http://server/image.jpg");

SyndicationCategory category = new SyndicationCategory("MyCategory");
category.Label = "categoryLabel";
category.Name = "categoryName";
category.Scheme = "categoryScheme";
feed.Categories.Add(category);

SyndicationItem item = new SyndicationItem("Item Title", "Item Content", new Uri("http://MyItemURI"));
item.Authors.Add(new SyndicationPerson("Jesper.Aaberg@contoso.com", "Jesper Aaberg", "http://Contoso/Aaberg"));
item.Categories.Add(category);
item.Contributors.Add(new SyndicationPerson("Lene.Aaling@contoso.com", "Lene Aaling", "http://Contoso/Aaling"));
item.Copyright = new TextSyndicationContent("Copyright 2007");
item.Id = "ItemID";
item.LastUpdatedTime = DateTime.Now;
item.PublishDate = DateTime.Today;
item.SourceFeed = feed;
item.Summary = new TextSyndicationContent("Item Summary");

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

SerializeFeed(feed);
Dim feed As New SyndicationFeed("My Feed Title", "My Feed Description", New Uri("http://MyFeedURI"))
feed.Copyright = New TextSyndicationContent("Copyright 2007")
feed.Language = "EN-US"
feed.LastUpdatedTime = DateTime.Now
feed.Generator = "Sample Code"
feed.Id = "FeedID"
feed.ImageUrl = New Uri("http://server/image.jpg")

Dim category As New SyndicationCategory("MyCategory")
category.Label = "categoryLabel"
category.Name = "categoryName"
category.Scheme = "categoryScheme"
feed.Categories.Add(category)

Dim item As New SyndicationItem("Item Title", "Item Content", New Uri("http://MyItemURI"))
item.Authors.Add(New SyndicationPerson("Jesper.Aaberg@contoso.com", "Jesper Aaberg", "http://Contoso/Aaberg"))
item.Categories.Add(category)
item.Contributors.Add(New SyndicationPerson("Lene.Aaling@contoso.com", "Lene Aaling", "http://Contoso/Aaling"))
item.Copyright = New TextSyndicationContent("Copyright 2007")
item.Id = "ItemID"
item.LastUpdatedTime = DateTime.Now
item.PublishDate = DateTime.Today
item.SourceFeed = feed
item.Summary = New TextSyndicationContent("Item Summary")
Dim items As New Collection(Of SyndicationItem)()
items.Add(item)
feed.Items = items

SerializeFeed(feed)

Im folgenden XML wird gezeigt, wie die SyndicationFeed in Atom 1.0 serialisiert wird.The following XML shows how the SyndicationFeed is serialized to Atom 1.0.

<?xml version="1.0" encoding="utf-8"?>  
<feed xml:lang="EN-US" xmlns="http://www.w3.org/2005/Atom">  
  <title type="text">My Feed Title</title>  
  <subtitle type="text">My Feed Description</subtitle>  
  <id>FeedID</id>  
  <rights type="text">Copyright 2007</rights>  
  <updated>2007-08-29T13:57:17-07:00</updated>  
  <category term="categoryName" label="categoryLabel" scheme="categoryScheme" />  
  <logo>http://server/image.jpg</logo>  
  <generator>Sample Code</generator>  
  <link rel="alternate" href="http://myfeeduri/" />  
  <entry>  
    <id>ItemID</id>  
    <title type="text">Item Title</title>  
    <summary type="text">Item Summary</summary>  
    <published>2007-08-29T00:00:00-07:00</published>  
    <updated>2007-08-29T13:57:17-07:00</updated>  
    <author>  
      <name>Jesper Aaberg</name>  
      <uri>http://Jesper/Aaberg</uri>  
      <email>Jesper@Aaberg.com</email>  
    </author>  
    <contributor>  
      <name>Lene Aaling</name>  
      <uri>http://Lene/Aaling</uri>  
      <email>Lene@Aaling.com</email>  
    </contributor>  
    <link rel="alternate" href="http://myitemuri/" />  
    <category term="categoryName" label="categoryLabel" scheme="categoryScheme" />  
    <content type="text">Item Content</content>  
    <rights type="text">Copyright 2007</rights>  
    <source>  
      <title type="text">My Feed Title</title>  
      <subtitle type="text">My Feed Description</subtitle>  
      <id>FeedID</id>  
      <rights type="text">Copyright 2007</rights>  
      <updated>2007-08-29T13:57:17-07:00</updated>  
      <category term="categoryName" label="categoryLabel" scheme="categoryScheme" />  
      <logo>http://server/image.jpg</logo>  
      <generator>Sample Code</generator>  
      <link rel="alternate" href="http://myfeeduri/" />  
    </source>  
  </entry>  
</feed>  

Im folgenden XML wird gezeigt, wie die SyndicationFeed in RSS 2.0 serialisiert wird.The following XML shows how the SyndicationFeed is serialized to RSS 2.0.

<?xml version="1.0" encoding="utf-8"?>  
<rss xmlns:a10="http://www.w3.org/2005/Atom" version="2.0">  
  <channel>  
    <title>My Feed Title</title>  
    <link>http://myfeeduri/</link>  
    <description>My Feed Description</description>  
    <language>EN-US</language>  
    <copyright>Copyright 2007</copyright>  
    <lastBuildDate>Wed, 29 Aug 2007 13:57:17 -0700</lastBuildDate>  
    <category domain="categoryScheme">categoryName</category>  
    <generator>Sample Code</generator>  
    <image>  
      <url>http://server/image.jpg</url>  
      <title>My Feed Title</title>  
      <link>http://myfeeduri/</link>  
    </image>  
    <a10:id>FeedID</a10:id>  
    <item>  
      <guid isPermaLink="false">ItemID</guid>  
      <link>http://myitemuri/</link>  
      <author>Jesper@Aaberg.com</author>  
      <category domain="categoryScheme">categoryName</category>  
      <title>Item Title</title>  
      <description>Item Summary</description>  
      <source>My Feed Title</source>  
      <pubDate>Wed, 29 Aug 2007 00:00:00 -0700</pubDate>  
      <a10:updated>2007-08-29T13:57:17-07:00</a10:updated>  
      <a10:rights type="text">Copyright 2007</a10:rights>  
      <a10:content type="text">Item Content</a10:content>  
      <a10:contributor>  
        <a10:name>Lene Aaling</a10:name>  
        <a10:uri>http://Lene/Aaling</a10:uri>  
        <a10:email>Lene@Aaling.com</a10:email>  
      </a10:contributor>  
    </item>  
  </channel>  
</rss>  

SyndicationItemSyndicationItem

Das folgende Codebeispiel zeigt, wie die SyndicationItem-Klasse in Atom 1.0 und RSS 2.0 serialisiert wird.The following code example shows how to serialize the SyndicationItem class to Atom 1.0 and RSS 2.0.

SyndicationItem item = new SyndicationItem("Item Title", "Item Content", new Uri("http://MyItemURI"));
item.Authors.Add(new SyndicationPerson("Jesper.Aaberg@contoso.com", "Jesper Aaberg", "http://Contoso/Aaberg"));
item.Authors.Add(new SyndicationPerson("Syed.Abbas@contoso.com", "Syed Abbas", "http://Contoso/Abbas"));

SyndicationCategory category = new SyndicationCategory("MyCategory");
category.Label = "categoryLabel";
category.Name = "categoryName";
category.Scheme = "categoryScheme";

SyndicationCategory category2 = new SyndicationCategory("MyCategoryTwo");
category2.Label = "categoryLabel";
category2.Name = "categoryName";
category2.Scheme = "categoryScheme";

item.Categories.Add(category);
item.Categories.Add(category2);
item.Contributors.Add(new SyndicationPerson("Lene.Aaling@contoso.com", "Lene Aaling", "http://Contoso/Aaling"));
item.Contributors.Add(new SyndicationPerson("Kim.Abercrombie@contoso.com", "Kim Abercrombie", "http://Contoso/Abercrombie"));
item.Copyright = new TextSyndicationContent("Copyright 2007");
item.Id = "ItemID";
item.LastUpdatedTime = DateTime.Now;
item.PublishDate = DateTime.Today;
item.SourceFeed = feed;
item.Summary = new TextSyndicationContent("Item Summary");

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

SerializeItem(item);
Dim item As New SyndicationItem("Item Title", "Item Content", New Uri("http://MyItemURI"))
item.Authors.Add(New SyndicationPerson("Jesper.Aaberg@contoso.com", "Jesper Aaberg", "http://Contoso/Aaberg"))
item.Authors.Add(New SyndicationPerson("Syed.Abbas@contoso.com", "Syed Abbas", "http://Contoso/Abbas"))

Dim category As New SyndicationCategory("MyCategory")
category.Label = "categoryLabel"
category.Name = "categoryName"
category.Scheme = "categoryScheme"

Dim category2 As New SyndicationCategory("MyCategoryTwo")
category2.Label = "categoryLabel"
category2.Name = "categoryName"
category2.Scheme = "categoryScheme"

item.Categories.Add(category)
item.Categories.Add(category2)
item.Contributors.Add(New SyndicationPerson("Lene.Aaling@contoso.com", "Lene Aaling", "http://Contoso/Aaling"))
item.Contributors.Add(New SyndicationPerson("Kim.Abercrombie@contoso.com", "Kim Abercrombie", "http://Contoso/Abercrombie"))
item.Copyright = New TextSyndicationContent("Copyright 2007")
item.Id = "ItemID"
item.LastUpdatedTime = DateTime.Now
item.PublishDate = DateTime.Today
item.SourceFeed = feed
item.Summary = New TextSyndicationContent("Item Summary")
Dim items As New Collection(Of SyndicationItem)()
items.Add(item)
feed.Items = items

SerializeItem(item)

Im folgenden XML wird gezeigt, wie die SyndicationItem in Atom 1.0 serialisiert wird.The following XML shows how the SyndicationItem is serialized to Atom 1.0.

<entry xmlns="http://www.w3.org/2005/Atom">  
  <id>ItemID</id>  
  <title type="text">Item Title</title>  
  <summary type="text">Item Summary</summary>  
  <published>2007-08-29T00:00:00-07:00</published>  
  <updated>2007-08-29T14:07:09-07:00</updated>  
  <author>  
    <name>Jesper Aaberg</name>  
    <uri>http://Contoso/Aaberg</uri>  
    <email>Jesper.Aaberg@contoso.com</email>  
  </author>  
  <author>  
    <name>Syed Abbas</name>  
    <uri>http://Contoso/Abbas</uri>  
    <email>Syed.Abbas@contoso.com</email>  
  </author>  
  <contributor>  
    <name>Lene Aaling</name>  
    <uri>http://Contoso/Aaling</uri>  
    <email>Lene.Aaling@contoso.com</email>  
  </contributor>  
  <contributor>  
    <name>Kim Abercrombie</name>  
    <uri>http://Contoso/Abercrombie</uri>  
    <email>Kim.Abercrombie@contoso.com</email>  
  </contributor>  
  <link rel="alternate" href="http://myitemuri/" />  
  <category term="categoryName" label="categoryLabel" scheme="categoryScheme" />  
  <category term="categoryName" label="categoryLabel" scheme="categoryScheme" />  
  <content type="text">Item Content</content>  
  <rights type="text">Copyright 2007</rights>  
  <source>  
    <title type="text">My Feed Title</title>  
    <subtitle type="text">My Feed Description</subtitle>  
    <link rel="alternate" href="http://myfeeduri/" />  
  </source>  
</entry>  

Im folgenden XML wird gezeigt, wie die SyndicationItem in RSS 2.0 serialisiert wird.The following XML shows how the SyndicationItem is serialized to RSS 2.0.

<item>  
  <guid isPermaLink="false">ItemID</guid>  
  <link>http://myitemuri/</link>  
  <author xmlns="http://www.w3.org/2005/Atom">  
    <name>Jesper Aaberg</name>  
    <uri>http://Jesper/Aaberg</uri>  
    <email>Jesper@Aaberg.com</email>  
  </author>  
  <author xmlns="http://www.w3.org/2005/Atom">  
    <name>Syed Abbas</name>  
    <uri>http://Contoso/Abbas</uri>  
    <email>Syed.Abbas@contoso.com</email>  
  </author>  
  <category domain="categoryScheme">categoryName</category>  
  <category domain="categoryScheme">categoryName</category>  
  <title>Item Title</title>  
  <description>Item Summary</description>  
  <source>My Feed Title</source>  
  <pubDate>Wed, 29 Aug 2007 00:00:00 -0700</pubDate>  
  <updated xmlns="http://www.w3.org/2005/Atom">2007-08-29T14:07:09-07:00</updated>  
  <rights type="text" xmlns="http://www.w3.org/2005/Atom">Copyright 2007</rights>  
  <content type="text" xmlns="http://www.w3.org/2005/Atom">Item Content</content>  
  <contributor xmlns="http://www.w3.org/2005/Atom">  
    <name>Lene Aaling</name>  
    <uri>http://Contoso/Aaling</uri>  
    <email>Lene.Aaling@contoso.com</email>  
  </contributor>  
  <contributor xmlns="http://www.w3.org/2005/Atom">  
    <name>Kim Abercrombie</name>  
    <uri>http://Contoso/Abercrombie</uri>  
    <email>Kim.Abercrombie@contoso.com</email>  
  </contributor>  
</item>  

SyndicationPersonSyndicationPerson

Das folgende Codebeispiel zeigt, wie die SyndicationPerson-Klasse in Atom 1.0 und RSS 2.0 serialisiert wird.The following code example shows how to serialize the SyndicationPerson class to Atom 1.0 and RSS 2.0.

SyndicationFeed feed = new SyndicationFeed("My Feed Title", "My Feed Description", new Uri("http://MyFeedURI"));
feed.Authors.Add(new SyndicationPerson("Jesper.Aaberg@contoso.com", "Jesper Aaberg", "http://Contoso/Aaberg"));
feed.Authors.Add(new SyndicationPerson("Syed.Abbas@contoso.com", "Syed Abbas", "http://Contoso/Abbas"));

feed.Contributors.Add(new SyndicationPerson("Lene.Aaling@contoso.com", "Lene Aaling", "http://Contoso/Aaling"));
feed.Contributors.Add(new SyndicationPerson("Kim.Abercrombie@contoso.com", "Kim Abercrombie", "http://Contoso/Abercrombie"));

SerializeFeed(feed);
Dim feed As New SyndicationFeed("My Feed Title", "My Feed Description", New Uri("http://MyFeedURI"))
feed.Authors.Add(New SyndicationPerson("Jesper.Aaberg@contoso.com", "Jesper Aaberg", "http://Contoso/Aaberg"))
feed.Authors.Add(New SyndicationPerson("Syed.Abbas@contoso.com", "Syed Abbas", "http://Contoso/Abbas"))

feed.Contributors.Add(New SyndicationPerson("Lene.Aaling@contoso.com", "Lene Aaling", "http://Contoso/Aaling"))
feed.Contributors.Add(New SyndicationPerson("Kim.Abercrombie@contoso.com", "Kim Abercrombie", "http://Contoso/Abercrombie"))

SerializeFeed(feed)

Im folgenden XML wird gezeigt, wie die SyndicationPerson in Atom 1.0 serialisiert wird.The following XML shows how the SyndicationPerson is serialized to Atom 1.0.

  <author>  
    <name>Jesper Aaberg</name>  
    <uri>http://Contoso/Aaberg</uri>  
    <email>Jesper.Aaberg@contoso.com</email>  
  </author>  
<contributor>  
    <name>Lene Aaling</name>  
    <uri>http://Contoso/Aaling</uri>  
    <email>Lene.Aaling@contoso.com</email>  
  </contributor>  

Das folgende XML zeigt, wie die SyndicationPerson-Klasse in RSS 2.0 serialisiert wird, wenn nur eine SyndicationPerson in der Authors-Auflistung bzw. der Contributors-Auflistung vorhanden ist.The following XML shows how the SyndicationPerson class is serialized to RSS 2.0 if only one SyndicationPerson exists in the Authors or Contributors collections, respectively.

<author>Jesper.Aaberg@contoso.com</author>  
<a10:contributor>  
    <a10:name>Lene Aaling</a10:name>  
    <a10:uri>http://Contoso/Aaling</a10:uri>  
    <a10:email>Lene.Aaling@contoso.com</a10:email>  
</a10:contributor>  

Das folgende XML zeigt, wie die SyndicationPerson-Klasse in RSS 2.0 serialisiert wird, wenn mehr als eine SyndicationPerson in der Authors-Auflistung bzw. der Contributors-Auflistung vorhanden ist.The following XML shows how the SyndicationPerson class is serialized to RSS 2.0 if more than one SyndicationPerson exists in the Authors or Contributors collections, respectively.

<a10:author>  
    <a10:name>Jesper Aaberg</a10:name>  
    <a10:uri>http://Contoso/Aaberg</a10:uri>  
    <a10:email>Jesper.Aaberg@contoso.com</a10:email>  
</a10:author>  
<a10:author>  
    <a10:name>Syed Abbas</a10:name>  
    <a10:uri>http://Contoso/Abbas</a10:uri>  
    <a10:email>Syed.Abbas@contoso.com</a10:email>  
</a10:author>  
<a10:contributor>  
    <a10:name>Lene Aaling</a10:name>  
    <a10:uri>http://Contoso/Aaling</a10:uri>  
    <a10:email>Lene.Aaling@contoso.com</a10:email>  
</a10:contributor>  
<a10:contributor>  
    <a10:name>Kim Abercrombie</a10:name>  
    <a10:uri>http://Contoso/Abercrombie</a10:uri>  
    <a10:email>Kim.Abercrombie@contoso.com</a10:email>  
</a10:contributor>  

Das folgende Codebeispiel zeigt, wie die SyndicationLink-Klasse in Atom 1.0 und RSS 2.0 serialisiert wird.The following code example shows how to serialize the SyndicationLink class to Atom 1.0 and RSS 2.0.

SyndicationFeed feed = new SyndicationFeed("My Feed Title", "My Feed Description", new Uri("http://MyFeedURI"));
feed.Links.Add(new SyndicationLink(new Uri("http://contoso/MyLink"), "alternate", "My Link Title", "text/html", 2048));

SerializeFeed(feed);
Dim feed As New SyndicationFeed("My Feed Title", "My Feed Description", New Uri("http://MyFeedURI"))
feed.Links.Add(New SyndicationLink(New Uri("http://contoso/MyLink"), "alternate", "My Link Title", "text/html", 2048))

SerializeFeed(feed)

Im folgenden XML wird gezeigt, wie die SyndicationLink in Atom 1.0 serialisiert wird.The following XML shows how the SyndicationLink is serialized to Atom 1.0.

<link rel="alternate" type="text/html" title="My Link Title" length="2048" href="http://contoso/MyLink" />

Im folgenden XML wird gezeigt, wie die SyndicationLink in RSS 2.0 serialisiert wird.The following XML shows how the SyndicationLink is serialized to RSS 2.0.

<a10:link rel="alternate" type="text/html" title="My Link Title" length="2048" href="http://contoso/MyLink" />

SyndicationCategorySyndicationCategory

Das folgende Codebeispiel zeigt, wie die SyndicationCategory-Klasse in Atom 1.0 und RSS 2.0 serialisiert wird.The following code example shows how to serialize the SyndicationCategory class to Atom 1.0 and RSS 2.0.

SyndicationFeed feed = new SyndicationFeed("My Feed Title", "My Feed Description", new Uri("http://MyFeedURI"));

SyndicationCategory category = new SyndicationCategory("MyCategory");
category.Label = "categoryLabel";
category.Name = "categoryName";
category.Scheme = "categoryScheme";
feed.Categories.Add(category);

SerializeFeed(feed);
Dim feed As New SyndicationFeed("My Feed Title", "My Feed Description", New Uri("http://MyFeedURI"))

Dim category As New SyndicationCategory("MyCategory")
category.Label = "categoryLabel"
category.Name = "categoryName"
category.Scheme = "categoryScheme"
feed.Categories.Add(category)

SerializeFeed(feed)

Im folgenden XML wird gezeigt, wie die SyndicationCategory in Atom 1.0 serialisiert wird.The following XML shows how the SyndicationCategory is serialized to Atom 1.0.

<category term="categoryName" label="categoryLabel" scheme="categoryScheme" />

Im folgenden XML wird gezeigt, wie die SyndicationCategory in RSS 2.0 serialisiert wird.The following XML shows how the SyndicationCategory is serialized to RSS 2.0.

<category domain="categoryScheme">categoryName</category>

TextSyndicationContentTextSyndicationContent

Im folgenden Codebeispiel wird gezeigt, wie die TextSyndicationContent-Klasse in Atom 1.0 und RSS 2.0 serialisiert wird, wenn TextSyndicationContent mit HTML-Inhalt erstellt wird.The following code example shows how to serialize the TextSyndicationContent class to Atom 1.0 and RSS 2.0 when TextSyndicationContent is created with HTML content.

SyndicationItem htmlItem = new SyndicationItem();
htmlItem.Content = new TextSyndicationContent("<html> some html </html>", TextSyndicationContentKind.Html);

SerializeItem(htmlItem);
Dim htmlItem As New SyndicationItem()
htmlItem.Content = New TextSyndicationContent("<html> some html </html>", TextSyndicationContentKind.Html)

SerializeItem(htmlItem)

Das folgende XML zeigt, wie die TextSyndicationContent-Klasse mit HTML-Inhalt in Atom 1.0 serialisiert wird.The following XML shows how the TextSyndicationContent class with HTML content is serialized to Atom 1.0.

<content type="html"><html> some html </html></content>

Das folgende XML zeigt, wie die TextSyndicationContent-Klasse mit HTML-Inhalt in RSS 2.0 serialisiert wird.The following XML shows how the TextSyndicationContent class with HTML content is serialized to RSS 2.0.

<description><html> some html </html></description>

Im folgenden Codebeispiel wird gezeigt, wie die TextSyndicationContent-Klasse in Atom 1.0 und RSS 2.0 serialisiert wird, wenn TextSyndicationContent mit Nur-Text-Inhalt erstellt wird.The following code example shows how to serialize the TextSyndicationContent class to Atom 1.0 and RSS 2.0 when TextSyndicationContent is created with plain text content.

SyndicationItem txtItem = new SyndicationItem();
txtItem.Content = new TextSyndicationContent("Some Plain Text", TextSyndicationContentKind.Plaintext);

SerializeItem(txtItem);
Dim txtItem As New SyndicationItem()
txtItem.Content = New TextSyndicationContent("Some Plain Text", TextSyndicationContentKind.Plaintext)

SerializeItem(txtItem)

Das folgende XML zeigt, wie die TextSyndicationContent-Klasse mit Nur-Text-Inhalt in Atom 1.0 serialisiert wird.The following XML shows how the TextSyndicationContent class with plain text content is serialized to Atom 1.0.

<content type="text">Some Plain Text</content>

Das folgende XML zeigt, wie die TextSyndicationContent-Klasse mit Nur-Text-Inhalt in RSS 2.0 serialisiert wird.The following XML shows how the TextSyndicationContent class with plain text content is serialized to RSS 2.0.

<description>Some Plain Text</description>

Im folgenden Codebeispiel wird gezeigt, wie die TextSyndicationContent-Klasse in Atom 1.0 und RSS 2.0 serialisiert wird, wenn TextSyndicationContent mit XHTML-Inhalt erstellt wird.The following code example shows how to serialize the TextSyndicationContent class to Atom 1.0 and RSS 2.0 when TextSyndicationContent is created with XHTML content.

SyndicationItem xhtmlItem = new SyndicationItem();
xhtmlItem.Content = new TextSyndicationContent("<html> some xhtml </html>", TextSyndicationContentKind.XHtml);

SerializeItem(xhtmlItem);
Dim xhtmlItem As New SyndicationItem()
xhtmlItem.Content = New TextSyndicationContent("<html> some xhtml </html>", TextSyndicationContentKind.XHtml)

SerializeItem(xhtmlItem)

Das folgende XML zeigt, wie die TextSyndicationContent-Klasse mit XHTML-Inhalt in Atom 1.0 serialisiert wird.The following XML shows how the TextSyndicationContent class with XHTML content is serialized to Atom 1.0.

<content type="xhtml">

<html> some xhtml </html>

</content>

Das folgende XML zeigt, wie die TextSyndicationContent-Klasse mit XHTML-Inhalt in RSS 2.0 serialisiert wird.The following XML shows how the TextSyndicationContent class with XHTML content is serialized to RSS 2.0.

<description><html> some xhtml </html></description>

UrlSyndicationContentUrlSyndicationContent

Das folgende Codebeispiel zeigt, wie die UrlSyndicationContent-Klasse in Atom 1.0 und RSS 2.0 serialisiert wird.The following code example shows how to serialize the UrlSyndicationContent class to Atom 1.0 and RSS 2.0.

SyndicationItem urlItem = new SyndicationItem();
urlItem.Content = new UrlSyndicationContent(new Uri("http://Contoso/someUrl"), "audio");

SerializeItem(urlItem);
Dim urlItem As New SyndicationItem()
urlItem.Content = New UrlSyndicationContent(New Uri("http://Contoso/someUrl"), "audio")

SerializeItem(urlItem)

Das folgende XML zeigt, wie die UrlSyndicationContent-Klasse in Atom 1.0 serialisiert wird.The following XML shows how the UrlSyndicationContent class is serialized to Atom 1.0.

<content type="audio" src="http://someurl/" />

Das folgende XML zeigt, wie die UrlSyndicationContent-Klasse mit XHTML-Inhalt in RSS 2.0 serialisiert wird.The following XML shows how the UrlSyndicationContent class with XHTML content is serialized to RSS 2.0.

<description />

<content type="audio" src="http://Contoso/someurl/" xmlns="http://www.w3.org/2005/Atom" />

XmlSyndicationContentXmlSyndicationContent

Das folgende Codebeispiel zeigt, wie die XmlSyndicationContent-Klasse in Atom 1.0 und RSS 2.0 serialisiert wird.The following code example shows how to serialize the XmlSyndicationContent class to Atom 1.0 and RSS 2.0.

SyndicationItem xmlItem = new SyndicationItem();

xmlItem.Title = new TextSyndicationContent("Xml Item Title");
xmlItem.Content = new XmlSyndicationContent("mytype", new SyndicationElementExtension(new SomeData()));

SerializeItem(xmlItem);
Dim xmlItem As New SyndicationItem()

xmlItem.Title = New TextSyndicationContent("Xml Item Title")
xmlItem.Content = New XmlSyndicationContent("mytype", New SyndicationElementExtension(New SomeData()))

SerializeItem(xmlItem)

Das folgende XML zeigt, wie die XmlSyndicationContent-Klasse in Atom 1.0 serialisiert wird.The following XML shows how the XmlSyndicationContent class is serialized to Atom 1.0.

<content type="mytype">

<SomeData xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/FeedMapping" />

</content>

Das folgende XML zeigt, wie die XmlSyndicationContent-Klasse mit XHTML-Inhalt in RSS 2.0 serialisiert wird.The following XML shows how the XmlSyndicationContent class with XHTML content is serialized to RSS 2.0.

<content type="mytype" xmlns="http://www.w3.org/2005/Atom">

<SomeData xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://schemas.datacontract.org/2004/07/FeedMapping" />

</content>

Siehe auchSee Also

Übersicht über WCF SyndicationWCF Syndication Overview
Architektur von SyndicationArchitecture of Syndication
Vorgehensweise: Erstellen eines grundlegenden RS-FeedsHow to: Create a Basic RSS Feed
Vorgehensweise: Erstellen eines grundlegenden Atom-FeedsHow to: Create a Basic Atom Feed
Vorgehensweise: Bereitstellen eines Feeds als Atom und RSSHow to: Expose a Feed as Both Atom and RSS