Name: SyndicationFeedReaderWriter
Owner: .NET Foundation
Description: A .NET Standard Library for reading and writing RSS 2.0 and ATOM 1.0 syndication feeds
Created: 2017-09-06 04:55:23.0
Updated: 2018-05-11 01:33:09.0
Pushed: 2018-05-17 17:54:56.0
Size: 291
Language: C#
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
Microsoft.SyndicationFeed.ReaderWriter provides lightweight forward-only read/write APIs (similar to .NET XmlReader) to simplify operations with RSS 2.0 (spec) and Atom (spec) syndication feeds. It offers extensiblity to support custom feed elements and formatting. The workflow is async on demand, which enables this library to be used on syndication feeds of arbitrary size or stream latency.
Examples can be found here.
g (var xmlReader = XmlReader.Create(filePath, new XmlReaderSettings() { Async = true }))
var feedReader = new RssFeedReader(xmlReader);
while(await feedReader.Read())
{
switch (feedReader.ElementType)
{
// Read category
case SyndicationElementType.Category:
ISyndicationCategory category = await feedReader.ReadCategory();
break;
// Read Image
case SyndicationElementType.Image:
ISyndicationImage image = await feedReader.ReadImage();
break;
// Read Item
case SyndicationElementType.Item:
ISyndicationItem item = await feedReader.ReadItem();
break;
// Read link
case SyndicationElementType.Link:
ISyndicationLink link = await feedReader.ReadLink();
break;
// Read Person
case SyndicationElementType.Person:
ISyndicationPerson person = await feedReader.ReadPerson();
break;
// Read content
default:
ISyndicationContent content = await feedReader.ReadContent();
break;
}
}
sw = new StringWriterWithEncoding(Encoding.UTF8);
g (XmlWriter xmlWriter = XmlWriter.Create(sw, new XmlWriterSettings() { Async = true, Indent = true }))
var writer = new RssFeedWriter(xmlWriter);
// Create item
var item = new SyndicationItem()
{
Title = "Rss Writer Avaliable",
Description = "The new Rss Writer is now available as a NuGet Package!",
Id = "https://www.nuget.org/packages/Microsoft.SyndicationFeed.ReaderWriter",
Published = DateTimeOffset.UtcNow
};
item.AddCategory(new SyndicationCategory("Technology"));
item.AddContributor(new SyndicationPerson("test", "test@mail.com"));
await writer.Write(item);
xmlWriter.Flush();
s StringWriterWithEncoding : StringWriter
private readonly Encoding _encoding;
public StringWriterWithEncoding(Encoding encoding)
{
this._encoding = encoding;
}
public override Encoding Encoding {
get { return _encoding; }
}