Tech-Today
RSS feed reader implementation in C#
Included in this page:
1.) Rss feed model (which you can customized according to your needs)
2.) Rss feed reader
My Objective is to read an rss feed of a news site like google and yahoo:
For example we want to read the RSS feed of yahoo news in the Philippines:
http://ph.news.yahoo.com/rss/most-popular-most-viewed-ph.xml
Note that the model also applies to google news since they have almost the same xml structure:
<item>
<title>Title</title>
<pubDate>Publication date</pubDate>
<description>Description</description>
</item>
First we need to setup a model where we will store the feed. Let's call this class RSSNews:
public class RssNews
{
public string Title;
public string PublicationDate;
public string Description;
}
Then you need a class to read a rss feed url:
using System.Collections.Generic;
using System.Net;
using System.Data;
using System.Linq;
public class RssReader
{
public static List<rssnews> Read(string url)
{
var webResponse = WebRequest.Create(url).GetResponse();
if (webResponse == null)
return null;
var ds = new DataSet();
ds.ReadXml(webResponse.GetResponseStream());
var news = (from row in ds.Tables["item"].AsEnumerable()
select new RssNews
{
Title = row.Field<string>("title"),
PublicationDate = row.Field<string>("pubDate"),
Description = row.Field<string>("description")
}).ToList();
return news;
}
}
*Make sure you include all the imports.
And finally, the code to call the reader, which you can place in your Page_Load event if you are working on a web app else Main method:
RssReader.Read("http://ph.news.yahoo.com/rss/most-popular-most-viewed-ph.xml");
-
How To Read And Write Csv Using Jackson Library
The sample code below demonstrates how we can read a csv file into an array of objects. Also it writes an array of objects into csv. To use don't forget to include in your pom.xml <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId>...
-
Mvc3 Dynamic Search Paging Using Pagedlist
Basically there's a great tutorial from this site: Unboxed solutions. -I've copied the codes and add some comments. I'll just try to add my own comments. 1.) First you need to install PagedList.Mvc from Nuget. a.) Go to Tools->Library Package...
-
Download Image Given A Url In C# Using The System.net.httpwebrequest Class
Saves image url object into the local machine /// /// Saves the list of url object into the output directory /// /// list of url path /// root directory that will be used for saving internal static void PhotoDownloader(ArrayList aList, string outputDir)...
-
Google Map Api - An Example Implementation In C#. Converts An Array Of String Addresses Into Longtitude, Latitude Pair
Objective: -To create a web application that will use the google map api to produce longtitude, latitude locations. The application will read string address values from an excel document. So it's also an excel reader. What you need: 1.) Visual Studio...
-
How To Add Unique Meta Tags, Description And Keywords To Blogger
Since, my google Webmaster's Tool Diagnostics always tells me that I have duplicate Short Description and Duplicate Meta Tags. I've search for solutions that will eliminate this problem. What I want is for every page of my blog there will be...
Tech-Today