本文整理汇总了C#中System.ServiceModel.Syndication.Rss20FeedFormatter.ReadFrom方法的典型用法代码示例。如果您正苦于以下问题:C# Rss20FeedFormatter.ReadFrom方法的具体用法?C# Rss20FeedFormatter.ReadFrom怎么用?C# Rss20FeedFormatter.ReadFrom使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.ServiceModel.Syndication.Rss20FeedFormatter
的用法示例。
在下文中一共展示了Rss20FeedFormatter.ReadFrom方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetRssFeedItems
public static List<SyndicationItem> GetRssFeedItems(string url)
{
Rss20FeedFormatter formatter = new Rss20FeedFormatter();
XmlReader reader;
try
{
reader = XmlReader.Create(url);
formatter.ReadFrom(reader);
}
catch(XmlException xexp)
{
string xml;
using (WebClient webClient = new WebClient())
{
xml = Encoding.UTF8.GetString(webClient.DownloadData(url));
}
xml = xml.Replace("BST", "+0100");
xml = xml.Replace("GMT", "+0000");
byte[] bytes = System.Text.UTF8Encoding.ASCII.GetBytes(xml);
reader = XmlReader.Create(new MemoryStream(bytes));
formatter.ReadFrom(reader);
}
reader.Close();
return formatter.Feed == null ? null : formatter.Feed.Items.ToList();
}
示例2: ParseXml
/// <summary>
/// Wybiera stronę na podstawie adresu url i zapisuje wszystkie wiadomości w kolekcji
/// </summary>
/// <param name="lineNews">Lista wiadomości</param>
/// <param name="category">Kategoria źródłowa do odczytu</param>
public void ParseXml(ObservableCollection<News> lineNews, Category category)
{
try
{
using (XmlReader reader = XmlReader.Create(category.Url))
{
var formatter = new Rss20FeedFormatter();
formatter.ReadFrom(reader);
foreach (var item in formatter.Feed.Items)
{
lineNews.Add(new News
{
Title = item.Title.Text,
Date = item.PublishDate.DateTime.ToString(),
UrlNews = item.Links.First().Uri.ToString(),
Description = item.Summary.Text,
Category = category.Name,
Id = item.Id
});
if (item.Links.Count > 1 && item.Links.Any(n => n.Uri.ToString().Contains(".jpg")))
lineNews.Last().UrlImage = item.Links[1].Uri.ToString();
ParseId(lineNews.Last());
ParseDescription(lineNews.Last());
}
}
}
catch (WebException ex)
{
MessageBox.Show(ex.Message, "Syndication Reader");
}
}
示例3: GetFeeds
public static IList<Feed> GetFeeds()
{
var urls = new[]
{
"http://www.simplyvinay.com/GetBlogRss.aspx", "http://www.bbc.co.uk/blogs/formula1/rss.xml",
"http://feeds.feedburner.com/AyendeRahien"
};
var list = new List<Feed>();
foreach (var url in urls)
{
using (var reader = new CustomXmlReader(url))
{
if (reader.ReadState == ReadState.Initial)
reader.MoveToContent();
var atom = new Atom10FeedFormatter();
if (atom.CanRead(reader))
{
atom.ReadFrom(reader);
list.AddRange(GenerateFeed(atom.Feed, true));
}
var rss = new Rss20FeedFormatter();
if (rss.CanRead(reader))
{
rss.ReadFrom(reader);
list.AddRange(GenerateFeed(rss.Feed, false));
}
}
}
return list;
}
示例4: GetPosts
public IEnumerable<SyndicationItem> GetPosts(string FeedUrl, int count)
{
using (XmlReader reader = XmlReader.Create(FeedUrl))
{
Rss20FeedFormatter feedFormatter = new Rss20FeedFormatter();
feedFormatter.ReadFrom(reader);
feedFormatter.PreserveElementExtensions = false;
return feedFormatter.Feed.Items.Take(3);
}
}
示例5: Page_Load
protected void Page_Load(object sender, EventArgs e)
{
XmlReader RSSReader = XmlReader.Create(ConfigurationManager.AppSettings["rssUri"]);
Rss20FeedFormatter formatter = new Rss20FeedFormatter();
formatter.ReadFrom(RSSReader);
lblTitle.Text = formatter.Feed.Title.Text;
lblDescription.Text = formatter.Feed.Description.Text;
hlRss.NavigateUrl = formatter.Feed.Links[0].Uri.AbsoluteUri;
lvRSS.DataSource = formatter.Feed.Items;
lvRSS.DataBind();
}
示例6: Research
public ActionResult Research()
{
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create("http://blog.firmus-software.co.uk/syndication.axd");
using (WebResponse response = request.GetResponse())
{
using (var reader = new XmlTextReader(response.GetResponseStream()))
{
Rss20FeedFormatter rssFeed = new Rss20FeedFormatter();
rssFeed.ReadFrom(reader);
return View(rssFeed.Feed);
}
}
}
示例7: GetFeed
public Rss20FeedFormatter GetFeed(string feedUrl)
{
var formatter = new Rss20FeedFormatter();
try
{
using (var reader = XmlReader.Create(feedUrl))
{
formatter.ReadFrom(reader);
}
}
catch (FileNotFoundException ex) { }
catch (WebException ex) { }
return formatter;
}
示例8: IsValidFeedUrl
// Kontrollerar så att parametern är av rss format.
public static bool IsValidFeedUrl(string url)
{
bool isValid = true;
try
{
XmlReader reader = XmlReader.Create(url);
Rss20FeedFormatter formatter = new Rss20FeedFormatter();
formatter.ReadFrom(reader);
reader.Close();
}
catch
{
isValid = false;
}
return isValid;
}
示例9: checkURL
internal static bool checkURL(string url)
{
bool URLcheck;
try {
XmlReader reader = XmlReader.Create(url);
Rss20FeedFormatter formatter = new Rss20FeedFormatter();
formatter.ReadFrom(reader);
reader.Close();
URLcheck = true;
}
catch{
Console.WriteLine("URL är felaktig");
URLcheck = false;
}
return URLcheck;
}
示例10: LoadFilterFeeds
protected override SyndicationFeedFormatter LoadFilterFeeds(IEnumerable<string> feedsToLoad,
IEnumerable<string> filterTags)
{
var formatter = new Rss20FeedFormatter();
var feedItems = new List<SyndicationItem>();
foreach (var feed in feedsToLoad)
{
try
{
using (XmlReader reader = XmlReader.Create(feed))
{
formatter.ReadFrom(reader);
feedItems.AddRange(formatter.Feed.Items);
}
}
catch (FileNotFoundException ex) { }
catch (WebException ex) { }
}
formatter.Feed.Items = FilterLoadedFeedItems(feedItems, filterTags);
return formatter;
}
示例11: ReadFrom_Feed
public void ReadFrom_Feed () {
string feed =
@"<rss version=""2.0"" xmlns:a10=""http://www.w3.org/2005/Atom""><channel><title>My Blog Feed</title><link>http://someuri/</link><description>This is a how to sample that demonstrates how to expose a feed using RSS with WCF</description><managingEditor>[email protected]</managingEditor><category>How To Sample Code</category><item><guid isPermaLink=""false"">ItemOneID</guid><link>http://localhost/Content/One</link><title>Item One</title><description>This is the content for item one</description><a10:updated>2008-06-02T10:13:13+03:00</a10:updated></item><item><guid isPermaLink=""false"">ItemTwoID</guid><link>http://localhost/Content/Two</link><title>Item Two</title><description>This is the content for item two</description><a10:updated>2008-06-02T10:13:13+03:00</a10:updated></item><item><guid isPermaLink=""false"">ItemThreeID</guid><link>http://localhost/Content/three</link><title>Item Three</title><description>This is the content for item three</description><a10:updated>2008-06-02T10:13:13+03:00</a10:updated></item></channel></rss>";
Rss20FeedFormatter f = new Rss20FeedFormatter ();
f.ReadFrom (CreateReader (feed));
Assert.IsNotNull (f.Feed, "#1");
}
示例12: AddURIItems_Click
// Add URI items
private void AddURIItems_Click(object sender, EventArgs e)
{
imageListView.SuspendLayout();
string query = "lemur";
string feedUrl = "http://search.yahooapis.com/ImageSearchService/rss/imageSearch.xml?appid=yahoosearchimagerss&query=" + query;
using (XmlReader reader = XmlReader.Create(feedUrl))
{
Rss20FeedFormatter rssFormatter = new Rss20FeedFormatter();
rssFormatter.ReadFrom(reader);
foreach (SyndicationItem rssItem in rssFormatter.Feed.Items)
{
if (rssItem.Links.Count > 0)
{
// Create a virtual item passing image URL as the item key.
string title = rssItem.Title.Text;
string link = rssItem.Links[0].Uri.ToString();
imageListView.Items.Add(link, title, uriAdaptor);
}
}
}
imageListView.ResumeLayout();
}
示例13: ReadFrom_WrongDate2
public void ReadFrom_WrongDate2 ()
{
Rss20FeedFormatter f = new Rss20FeedFormatter ();
f.ReadFrom (CreateReader ("<rss version='2.0'><channel><lastBuildDate>2000-01-01T00:00:00</lastBuildDate></rss></channel>"));
}
示例14: ReadFrom_Docs
public void ReadFrom_Docs ()
{
Rss20FeedFormatter f = new Rss20FeedFormatter ();
f.ReadFrom (CreateReader ("<rss version='2.0'><channel><docs>documents</docs></channel></rss>"));
Assert.IsNotNull (f.Feed, "#1");
// 'docs' is treated as extensions ...
Assert.AreEqual (1, f.Feed.ElementExtensions.Count, "#2");
}
示例15: ReadFrom1
public void ReadFrom1 ()
{
Rss20FeedFormatter f = new Rss20FeedFormatter ();
Assert.IsNull (f.Feed, "#1");
f.ReadFrom (CreateReader ("<rss version='2.0'><channel><title>test</title></channel></rss>"));
SyndicationFeed feed1 = f.Feed;
Assert.IsNotNull (f.Feed.Title, "#2");
Assert.AreEqual ("test", f.Feed.Title.Text, "#3");
f.ReadFrom (CreateReader ("<rss version='2.0'><channel><title>test</title></channel></rss>"));
Assert.IsFalse (object.ReferenceEquals (feed1, f.Feed), "#4");
}