SyndicationFeed Classe

Definizione

Rappresenta un oggetto feed di primo livello, <feed> in Atom 1.0 e <rss> in 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
Ereditarietà
SyndicationFeed
Attributi

Esempio

Il codice seguente illustra come creare un'istanza SyndicationFeed e serializzarla sia in Atom 1.0 che in 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()

Il codice XML seguente mostra come un oggetto SyndicationFeed viene serializzato in 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>

Nel codice XML seguente viene illustrato come serializzare un'istanza SyndicationFeed in 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>

Commenti

Se serializzato in Atom 1.0, un'istanza SyndicationFeed viene scritta in un <feed> elemento . Nella tabella seguente viene illustrato il modo in cui ogni proprietà definita nella SyndicationFeed classe viene serializzata in Atom 1.0.

Proprietà SyndicationFeed Modulo serializzato
AttributeExtensions Attributo nell'elemento <feed> per ogni attributo nella raccolta.
Authors Elemento <author> per ogni SyndicationPerson oggetto dell'insieme.
Categories Elemento <category> per ogni SyndicationCategory oggetto dell'insieme.
Contributors Elemento <contributor> per ogni SyndicationPerson oggetto dell'insieme.
Copyright Elemento <rights> .
Description Elemento <subtitle> .
ElementExtensions Ogni elemento della raccolta viene scritto all'interno dell'elemento <feed> .
Generator Elemento <generator> .
Id Elemento <id>.
ImageUri Elemento <logo> .
Items Elemento <entry> per ogni SyndicationItem oggetto dell'insieme.
Language Non serializzato.
LastUpdatedTime Elemento <updated>.
Links Elemento <link> per ogni SyndicationLink oggetto dell'insieme.
Title Elemento <title> .

Se serializzato in RSS 2.0, un'istanza SyndicationFeed viene scritta in un <rss> elemento . Nella tabella seguente viene illustrato il modo in cui ogni proprietà definita nella SyndicationFeed classe viene serializzata in RSS 2.0.

Proprietà SyndicationFeed Modulo serializzato
AttributeExtensions Attributo nell'elemento <channel> per ogni attributo nella raccolta.
Authors Elemento <managingEditor> se ne è presente solo uno SyndicationPerson nell'insieme; in caso contrario, un <a10:author> elemento per ognuno SyndicationPerson dell'insieme.
Categories Elemento <category> per ogni SyndicationCategory oggetto dell'insieme.
Contributors Elemento <a10:contributor> per ogni SyndicationPerson oggetto dell'insieme.
Copyright Elemento <copyright> .
Description Elemento <description> .
ElementExtensions Ogni elemento della raccolta viene scritto all'interno dell'elemento <channel> .
Generator Elemento <generator> .
Id Elemento <a10:id>.
ImageUri Elemento <image>.
Items Elemento <item> per ogni SyndicationItem oggetto dell'insieme.
Language Elemento <language> .
LastUpdatedTime Elemento <lastBuildDate> .
Links Elemento <a10:link> per ogni SyndicationLink oggetto dell'insieme.
Title Elemento <title> .

Costruttori

Nome Descrizione
SyndicationFeed()

Inizializza una nuova istanza della classe SyndicationFeed.

SyndicationFeed(IEnumerable<SyndicationItem>)

Inizializza una nuova istanza della SyndicationFeed classe con la raccolta di SyndicationItem oggetti specificata.

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

Inizializza una nuova istanza della SyndicationFeed classe con il titolo, la descrizione, l'URI e la raccolta di SyndicationItem oggetti specificati.

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

Crea una nuova istanza della SyndicationFeed classe .

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

Crea una nuova istanza della SyndicationFeed classe .

SyndicationFeed(String, String, Uri)

Inizializza una nuova istanza della classe con il titolo, la SyndicationFeed descrizione e l'URI (Uniform Resource Identifier) specificati.

SyndicationFeed(SyndicationFeed, Boolean)

Crea una nuova istanza della SyndicationFeed classe con il feed specificato.

Proprietà

Nome Descrizione
AttributeExtensions

Ottiene una raccolta di estensioni degli attributi.

Authors

Ottiene una raccolta di autori del feed.

BaseUri

Ottiene o imposta l'URI di base per l'istanza SyndicationFeed di .

Categories

Ottiene una raccolta di categorie per il feed.

Contributors

Ottiene una raccolta di collaboratori al feed.

Copyright

Ottiene o imposta informazioni sul copyright per il feed.

Description

Ottiene o imposta una descrizione del feed.

Documentation

Ottiene o imposta il collegamento alla documentazione per il feed.

ElementExtensions

Ottiene le estensioni degli elementi per il feed.

Generator

Ottiene o imposta il generatore del feed.

Id

Ottiene o imposta l'ID del feed.

ImageUrl

Ottiene o imposta l'URL dell'immagine per il feed.

Items

Ottiene una raccolta degli elementi del feed contenuti nel feed.

Language

Ottiene o imposta la lingua del feed.

LastUpdatedTime

Ottiene o imposta l'ora dell'ultimo aggiornamento del feed.

Links

Ottiene i collegamenti associati al feed.

SkipDays

Ottiene una raccolta di stringhe che indica il set di valori nell'elemento 'skipDays' per il feed.

SkipHours

Ottiene una raccolta di numeri interi che indicano il set di valori nell'elemento 'skipHours' per il feed.

TextInput

Ottiene o imposta la proprietà TextInput per il feed.

TimeToLive

Ottiene o imposta l'attributo 'ttl' per il feed.

Title

Ottiene o imposta il titolo del feed.

Metodi

Nome Descrizione
Clone(Boolean)

Crea una copia dell'istanza SyndicationFeed .

CreateCategory()

Crea una nuova istanza di SyndicationCategory.

CreateItem()

Crea una nuova istanza di SyndicationItem.

CreateLink()

Crea una nuova istanza di SyndicationLink.

CreatePerson()

Crea una nuova istanza di SyndicationPerson.

Equals(Object)

Determina se l'oggetto specificato è uguale all'oggetto corrente.

(Ereditato da Object)
GetAtom10Formatter()

Ottiene un'istanza Atom10FeedFormatter di .

GetHashCode()

Funge da funzione hash predefinita.

(Ereditato da Object)
GetRss20Formatter()

Ottiene un'istanza Rss20FeedFormatter di .

GetRss20Formatter(Boolean)

Ottiene una nuova Rss20FeedFormatter istanza.

GetType()

Ottiene il Type dell'istanza corrente.

(Ereditato da Object)
Load(XmlReader)

Carica un feed di diffusione dal lettore XML specificato.

Load<TSyndicationFeed>(XmlReader)

Carica un'istanza SyndicationFeedderivata da dall'oggetto specificato XmlReader.

MemberwiseClone()

Crea una copia superficiale del Objectcorrente.

(Ereditato da Object)
SaveAsAtom10(XmlWriter)

Scrivere il feed di diffusione nell'oggetto specificato XmlWriter in formato Atom 1.0.

SaveAsRss20(XmlWriter)

Scrivere il feed di diffusione nel formato RSS 2.0 specificato XmlWriter .

ToString()

Restituisce una stringa che rappresenta l'oggetto corrente.

(Ereditato da Object)
TryParseAttribute(String, String, String, String)

Tenta di analizzare un'estensione dell'attributo.

TryParseElement(XmlReader, String)

Tenta di analizzare un'estensione dell'elemento.

WriteAttributeExtensions(XmlWriter, String)

Scrive le estensioni dell'attributo nell'oggetto specificato XmlWriter usando la versione di diffusione specificata.

WriteElementExtensions(XmlWriter, String)

Scrive le estensioni degli elementi nell'oggetto specificato XmlWriter usando la versione di diffusione specificata.

Si applica a