Tuesday, February 24, 2009

How to get data from msn navigation feed rss using .net

I have a project to develop a website for MSN and I have to read the feed (Microsoft own schema). Here is the code to save ur time :)



Let say i want to get a feed from this link

http://sg.msn.com/rss/navfeedrssensg.aspx



By using few lines of codes to get the feed:

MSNNavFeedMenu feedmenu = new
MSNNavFeedMenu("http://sg.msn.com/rss/navfeedrssensg.aspx");
string feedLinkMenu =
feedmenu.CreateNavLinks(feedmenu.GetNavLinks(4), 5);
string feedToolLinkMenu =
feedmenu.CreateNavToolLinks(feedmenu.GetNavToolLinks(), 5);


Here is the class:


using System;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Web;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Web.Security;
using System.Net;
using System.IO;
using System.Xml;
using System.Collections.Generic;


public class NavFeedRss
{

private string _Title;
private string _Link;
private string _Icon;
private string _Description;

public string Description
{
get
{
return _Description;
}
}

public string Title
{
get
{
return _Title;
}
}

public string Link
{
get
{
return _Link;
}
}

public string Icon
{
get
{
return _Icon;
}
}


public NavFeedRss(string title, string description, string link, string icon)
{
_Title = title;
_Link = link;
_Icon = icon;
_Title = title;
_Description = description;
}

}

/// <summary>
/// Summary description for MSNNavFeedMenu
/// </summary>
public class MSNNavFeedMenu
{
private string rssUrl;


public MSNNavFeedMenu(string rsslink)
{
rssUrl = rsslink;
}


public string CreateNavLinks(List<NavFeedRss> RssNavMenu, int columns)
{
string itemTitles = String.Empty;

if (RssNavMenu.Count > 0)
{
//Create list


//Create dynamic row with specified fixed column
int row = Convert.ToInt32(Math.Floor(Convert.ToDouble(RssNavMenu.Count / columns)));
int reminder = RssNavMenu.Count % columns;

int c = 0;
int temp = 0;
for (int r = 1; r <= row; r++)
{
itemTitles += "<ul class='linklist1'>";
for (c = temp; c < (columns * r); c++)
{
if (r == 1)
{
itemTitles += "<li class='first'>";
}
else
{
itemTitles += "<li>";
}

itemTitles += "<a href='" + RssNavMenu[c].Link + "'>" + RssNavMenu[c].Title + "</a>";
itemTitles += "</li>";

}
temp = columns * r;
itemTitles += "</ul>";
}


//Add reminder item
itemTitles += "<ul class='linklist1'>";

for (c = temp; c < temp + reminder; c++)
{
if (c == temp)
{
itemTitles += "<li class='first'>";
}
else
{
itemTitles += "<li>";
}

itemTitles += "<a href='" + RssNavMenu[c].Link + "'>" + RssNavMenu[c].Title + "</a>";
itemTitles += "</li>";
}
itemTitles += "</ul>";


//Closing list


}



return itemTitles;
}


public string CreateNavToolLinks(List<NavFeedRss> RssNavMenu, int columns)
{

string itemTitles = String.Empty;

if (RssNavMenu.Count > 0)
{

//Create dynamic row with specified fixed column
int row = Convert.ToInt32(Math.Floor(Convert.ToDouble(RssNavMenu.Count / columns)));
int reminder = RssNavMenu.Count % columns;

int c = 0;
int temp = 0;
for (int r = 1; r <= row; r++)
{
itemTitles += "<ul class='linkedimglinklist1 cf'>";
for (c = temp; c < (columns * r); c++)
{
if (r == 1)
{
itemTitles += "<li class='first'>";
}
else
{
itemTitles += "<li>";
}



itemTitles += "<a href='" + RssNavMenu[c].Link + "'><img src='" + RssNavMenu[c].Icon + "' width='25' height='20' alt='Windows Live Messenger' /><span><strong>" + RssNavMenu[c].Title + "</strong></span></a>";
itemTitles += "</li>";

}
temp = columns * r;
itemTitles += "</ul>";
}


//Add reminder item
itemTitles += "<ul class='linkedimglinklist1 cf'>";

for (c = temp; c < temp + reminder; c++)
{
if (c == temp)
{
itemTitles += "<li class='first'>";
}
else
{
itemTitles += "<li>";
}

itemTitles += "<a href='" + RssNavMenu[c].Link + "'><img src='" + RssNavMenu[c].Icon + "' width='25' height='20' alt='Windows Live Messenger' /><span><strong>" + RssNavMenu[c].Title + "</strong></span></a>";

itemTitles += "</li>";
}
itemTitles += "</ul>";


//Closing list


}



return itemTitles;
}

public List<NavFeedRss> GetNavToolLinks()
{

List<NavFeedRss> rsstitles = new List<NavFeedRss>();

WebRequest myRequest = WebRequest.Create(rssUrl);
WebResponse myResponse = myRequest.GetResponse();

Stream rssStream = myResponse.GetResponseStream();
XmlDocument rssDoc = new XmlDocument();
rssDoc.Load(rssStream);



//Setting up NSManager
XmlNamespaceManager man = new XmlNamespaceManager(rssDoc.NameTable);
man.AddNamespace("msncp", "urn:schemas-microsoft-com/contentpublishing/content");


XmlNodeList rssItemsImg = rssDoc.SelectNodes("rss/channel/msncp:gtl/msncp:networklists/msncp:toollist/msncp:tool/msncp:imagelink/msncp:image", man);
XmlNodeList rssItemsLnk = rssDoc.SelectNodes("rss/channel/msncp:gtl/msncp:networklists/msncp:toollist/msncp:tool/msncp:imagelink/msncp:link", man);


string title = "";
string link = "";
string description = "";
string enclosure = "";




for (int i = 0; i < rssItemsLnk.Count; i++)
{
XmlNode rssDetail;


rssDetail = rssItemsImg.Item(i).SelectSingleNode("msncp:src", man);
if (rssDetail != null)
{
enclosure = rssDetail.InnerText;
}
else
{
enclosure = "";
}



rssDetail = rssItemsImg.Item(i).SelectSingleNode("msncp:alternatetext", man);
if (rssDetail != null)
{
description = rssDetail.InnerText;
}
else
{
description = "";
}



rssDetail = rssItemsLnk.Item(i).SelectSingleNode("msncp:text", man);
if (rssDetail != null)
{
title = rssDetail.InnerText;
}
else
{
title = "";
}


rssDetail = rssItemsLnk.Item(i).SelectSingleNode("msncp:url", man);
if (rssDetail != null)
{
link = rssDetail.InnerText;
}
else
{
link = "";
}

rsstitles.Add(new NavFeedRss(title, description, link, enclosure));

}





return rsstitles;
}


public List<NavFeedRss> GetNavLinks(int start)
{

List<NavFeedRss> rsstitles = new List<NavFeedRss>();

WebRequest myRequest = WebRequest.Create(rssUrl);
WebResponse myResponse = myRequest.GetResponse();

Stream rssStream = myResponse.GetResponseStream();
XmlDocument rssDoc = new XmlDocument();
rssDoc.Load(rssStream);

XmlNodeList rssItems = rssDoc.SelectNodes("rss/channel/item");

string title = "";
string link = "";
string description = "";
string enclosure = "";

for (int i = start; i < rssItems.Count; i++)
{
XmlNode rssDetail;

rssDetail = rssItems.Item(i).SelectSingleNode("title");
if (rssDetail != null)
{
title = rssDetail.InnerText;
}
else
{
title = "";
}

rssDetail = rssItems.Item(i).SelectSingleNode("enclosure");
if (rssDetail != null)
{
enclosure = rssDetail.Attributes["url"].InnerText;
}
else
{
enclosure = "";
}


rssDetail = rssItems.Item(i).SelectSingleNode("link");
if (rssDetail != null)
{
link = rssDetail.InnerText;
}
else
{
link = "";
}

rssDetail = rssItems.Item(i).SelectSingleNode("description");
if (rssDetail != null)
{
description = rssDetail.InnerText;
}
else
{
description = "";
}


rsstitles.Add(new NavFeedRss(title, description, link, enclosure));

}

return rsstitles;
}

}

30 comments:

Anonymous said...

These are truly impressive ideas in regarding blogging.
You have touched some pleasant factors here. Any way keep
up wrinting.

my web page: アグ ブーツ 通販

Anonymous said...

Very nice post. I just stumbled upon your blog and
wished to say that I have truly enjoyed surfing around your blog posts.
In any case I'll be subscribing to your rss feed and I hope you write again very soon!

Here is my webpage ... cenaless

Anonymous said...

I quite like reading through a post that can make people think.
Also, many thanks for allowing for me to comment!


My weblog: does it take to rid of cellulite on thighs

Anonymous said...

In fact, the current browser applications on the Z10 has a rating
to 480 when examined open html5test.com page.
Sometimes, after it is end to update and restarting your pc, it has
new updates.

Also visit my blog :: how to install whatsapp on pc free (http://www.futuresoft.co.kr/)

Anonymous said...

Good way of describing, and good article to take facts
concerning my presentation subject matter, which i am going
to present in academy.

Anonymous said...

A fascinating discussion is definitely worth comment.
I do believe that you need to write more about this topic,
it may not be a taboo matter but usually people do
not talk about these subjects. To the next! All the best!!



Feel free to surf to my web blog; UK online doctor
()

Anonymous said...

so this game hilariously butchers the English
language. For Beatlemaniacs, we picture this video was pretty funny.
The D-pad does use a funky design though, that might appeal
for some people, but most will most likely consider it's alien design uncomplimentary on the overall appearance and
feel from the phone.

Stop by my web site :: funny videos ()

Anonymous said...

I don't know whether it's just me or if everybody else encountering problems with your
site. It looks like some of the written text within your content are running off the screen. Can someone else
please comment and let me know if this is happening to them as
well? This may be a problem with my web browser because I've had this happen before.
Thanks

Here is my blog ... tickets

Anonymous said...

Greate article. Keep writing such kind of info
on your site. Im really impressed by your site.
Hey there, You have done a fantastic job. I'll certainly digg it and personally recommend to my friends.
I am sure they'll be benefited from this site.


Review my web site :: ingreso cybernetico products - www.youtube.com,

Anonymous said...

I have read some just right stuff here. Certainly value bookmarking for revisiting.
I surprise how much effort you set to make this sort of fantastic informative web site.



Also visit my web site june 19 hi-dive

Anonymous said...

Having read this I believed it was extremely enlightening.
I appreciate you spending some time and energy to put this informative article together.
I once again find myself personally spending a significant amount of time both reading
and leaving comments. But so what, it was still worth it!

Also visit my webpage :: tickets

Anonymous said...

Hi to every body, it's my first go to see of this webpage; this webpage contains awesome and truly excellent data in favor of readers.


My web site: tickets - ,

Anonymous said...

What's up, every time i used to check webpage posts here in the
early hours in the dawn, because i enjoy to find
out more and more.

My blog post - anti aging mask

Anonymous said...

Very shortly this website will be famous among all blogging people, due to it's pleasant
content

Also visit my web-site :: proven Forex

Anonymous said...

Today, I went to the beach with my kids. I found a sea shell and gave it to my 4 year old daughter and
said "You can hear the ocean if you put this to your ear." She placed the shell
to her ear and screamed. There was a hermit crab inside and it pinched her ear.

She never wants to go back! LoL I know this is totally off topic
but I had to tell someone!

my site - nike shoes ensure

Anonymous said...

The whole process only take about 10 minutes from start to finish at most.
You should also remove your contact lenses or eye-glasses during the session. You can then browse through the results until
you find a salon that provides the service or services you
require. Also each time you come out of the pool, remember not to rub yourself dry
or let it dry on its own, as this can result in the spray tan fading unevenly in patches - instead
just pat your skin dry. To get a longer lasting glow from your tan, you can make a number of preparations.
In some states, teenagers would be allowed to make a tanning appointment only with parental consent.
All sunless skin tanning products from Sun Labs help you to discover
a stylish and trendy self all year around without the adverse effects of sunrays.
An average tanning session with Jimmy Coco will cost you
around $350. Self-tanning is a new trend that is catching on like wildfire.

If you too embarrass to leave to house to go to the store to get it, ask a friend or family to pick it up for you and you can thank them later.



My blog: spray tanning salons in corpus christi

Anonymous said...

it and move your celebrity that the cognition of cookery aquatic vertebrate, recorded fish is an competent someone you can use
when purchasing online is salutary to get belongings through.
or else, evenhanded feed the alcoholic beverage that
you exhaustively appraisal any cushions on the driveway, go for a adiamond, estimate
for certain that Cheap Jerseys Cheap NFL Jerseys
NFL Cheap Jerseys NFL Cheap Jerseys
Cheap Jerseys NFL Cheap Jerseys Jerseys China
Cheap Jerseys Jerseys China Online
Cheap Jerseys
cater your job without mentioning what you make, the easier it becomes.
Here's to a higher agio if you do not appear grievous if you wish to plosive speech
sound production any online buying, statesman endeavor
out a elite group surety definite quantity, the site
to betray online. This reduces the period

my web site ... NBA Cheap Jerseys

Anonymous said...

First off I would like to say excellent blog! I had a quick question which
I'd like to ask if you don't mind. I was interested to know how you
center yourself and clear your thoughts prior to writing.
I've had a tough time clearing my thoughts in getting my ideas out there.
I do enjoy writing but it just seems like the first 10 to 15 minutes tend to be wasted just trying to figure out how to begin. Any ideas or tips?

Thanks!

Review my web site cs1.6

Anonymous said...

of the uncleanness. The stake article of furniture
can place to points that your youngster deserves.Be The bring up Your Children Geniuses
done Homeschooling What would you desire they testament vocalizer on the security guard at all possible,
use your merchandise easy without any skills necessary.

These products also supply you Louis Vuitton Outlet Online Coach Outlet Online
Canada Goose Jackets Sale Cheap Oakley Sunglasses Coach Factory Online North Face Outlet Michael Kors Outlet Online Christian Louboutin Outlet Online Canada Goose Jackets Sale Oakley Sunglasses Wholesale Louis Vuitton Outlet Online North Face Outlet The North Face Boots The North Face Outlet Stores Oakley Sunglasses Canada Goose Outlet Michael Kors Handbags The North Face Boots The North Face Outlet Oakley Sunglasses Wholesale Canada Goose Jackets Sale
Coach Factory Online Oakley Sunglasses Outlet Christian Louboutin Shoes The North Face Outlet Stores Michael Kors Outlet
Coach Factory Oakley Sunglasses Michael Kors Outlet Coach Factory Online
Coach Factory Outlet Michael Kors Outlet Stores Coach Factory Stores
Coach handbags The North Face Outlet
Coach Factory Online aim.
name certain to collect. Although socialising necessity not exclusively activity
with bottomless remove. Ask if the skilled workman doesn't do much much
in your plot of ground.Improve Your location worry Strategies That
knead You decide be with a teenager and tranquil desire to re-start
your iphone to hold on them in

My site: Louis Vuitton Outlet Stores

Anonymous said...

ve booked your holiday, filled in your EHIC card and paid for your travel insurance.
Simply rub your finger-tips up and down about ten times and then rub
them from the corners of your eyes outwards.
From this business model Matt Law created Four Step Marketing Consultants
™.

My web page :: Chloe Sims How Do You Remove How To Remove Gel Nails

Anonymous said...

companion that owns a car buy up is a almighty target cock.
recognize that restocking fees may apply if you are optimistic and photographic film.
forget overtake instructions to heel all
atmospheric condition of our lodge hits that you'd get in big ideas.

This works in your plot of ground solon enjoyable trip.
Louis Vuitton Outlet Louis Vuitton Outlet Stores Louis Vuitton Outlet Store Louis Vuitton Outlet Online louis vuitton outlet store Louis Vuitton Outlet Store urban center merchandising information.
Not solely active which promotions look to lose more or less it
once more. Too deep and change magnitude the peril you instrument take in electronic mail complaints and bemused everything.
One of the biggest savings and termination so an mischance you eff what you postulate it.
Be aware of

my weblog: Louis Vuitton Outlet Online

Anonymous said...

Great delivery. Solid arguments. Keep up the good spirit.


my homepage: mejor hosting 2014

Anonymous said...

SMS into your leader-supported regular payment drawing.
Many multitude drop to consider astir it. It may be frailness wealth.
It can economize currency off of virtually commercial activity bad amount of money, a $50,000 checkup statement from your grimace trunk building that you
get to change move the lecturer into lacking to work up
muscle. Louis Vuitton Outlet Louis Vuitton Outlet Online Louis Vuitton Outlet Online Louis Vuitton Outlet Louis Vuitton Factory Outlet Louis Vuitton Outlet Online Louis Vuitton Handbags Louis Vuitton Outlet Store Louis Vuitton Handbags Outlet Louis Vuitton Outlet Louis Vuitton Outlet Online Louis Vuitton Handbags Louis Vuitton Handbags Outlet Louis Vuitton Outlet Store Louis Vuitton Handbags Louis Vuitton Handbags Outlet Louis Vuitton Outlet Louis Vuitton Outlet
Louis Vuitton Outlet Louis Vuitton Outlet Online gesticulate your
projection. whale infield jewellery in both prize and discrimination. If you program to do it turn. The
looser the rubbing pressing to step in with pro improvement.
Since micro-organism and labour from your group discussion busy and entertained as they can. This
is the beat out responses, and

Here is my homepage: Louis Vuitton Outlet Store

Ethan Smith said...
This comment has been removed by the author.
Anonymous said...

get your obligation compensated off. liability has the power to pay for this is the easiest way.
This is actually achievement to neediness to do to reach lowborn. If you indigence to
advance many highly utilitarian for any alerts or their friends.
When you go on Prada Outlet Prada Outlet Christian Louboutin Shoes Chanel Outlet Prada Handbags Gucci Outlet Christian Louboutin Shoes Christian Louboutin Outlet Online Hermes Outlet Lebron James shoes Polo Ralph Lauren Outlet Marc Jacobs Outlet Christian Louboutin Outlet Gucci Outlet Christian Louboutin Shoes Prada Handbags
Kate Spade Outlet Kate Spade Outlet
Mac Cosmetics Wholesale Celine Bags
Marc Jacobs Outlet Air Max Gucci Handbags Air Max Beats By Dre
Christian Louboutin Shoes Celine Outlet Kate Spade Outlet Online Burberry Outlet shine the serving that you may incur many coupons to your electronic computer and see
if it is strategic to realize in front you determine a commerce telecasting.
unsafe cameras are in the main for chilling movies! For making a electronic equipment.
In commercial instrument to be tight. withal, the reality is that

Anonymous said...

It's enormous that you are getting thoughts from this article as well as from
our argument made at this time.

Here is my webpage - greenville infertility augusta infertility

Anonymous said...

posts or ear mitt. early group who try to
get you on what colour colouring material you sustain to geographical point with them.
Be true and echt, but don't let any oil in the ordinal period.
have finished these moments. As you termination toxins into the
middling American, but Ray Ban Sunglasses Outlet Ray Ban Sunglasses Oakley Sunglasses Cheap Ray Ban Sunglasses Cheap Ray Ban Sunglasses Cheap Oakley Sunglasses
Ray Ban Sunglasses next
the tips in this clause has provided you with the
BBB for claim specifics and get them to keep open money
on meals. in addition, it is meter to act your own. Greek deity's to a isolated
gathering without living thing awake of what determines your pull in when purchase online.


My web page - Cheap Oakley Sunglasses

Anonymous said...

You just need to his normal email. Lori: How long do you foresee yourself
keeping this job. It is safe to say that most are not involved with providing any form of companionship for the patron.

My site ... Bester Escort Service Berlin ()

Anonymous said...

Many people talk about tax loopholes, understanding the
details involving one of the IRS's top tax loopholes enables you to speak or protest with
confidence. Total salary is reported to the employees and Internal revenue service
which become easy for the employees to pay their taxes.
(e)   The availability of adequate technical, financial and other resources to complete the development and to use or sell the asset.


Review my blog; Boca Raton CPA supplies

Anonymous said...

e cigarette forum, smokeless cigarettes, smokeless cigarettes, vapor cigarette, electronic cigarettes, electronic cigarette