Asp.Net: Caching Rss feeds

by Pieter Brinkman 3. March 2009 09:10

For dotNetSearch.net I needed to cache the RSS feed (on the right). I did this with the .Net Cache namespace.

if(Cache.Get(RssUrl) == null)
{
 RssDocument rssFeed = RssDocument.Load(new Uri(RssUrl));
 Cache.Insert(RssUrl, XDocument.Parse(rssFeed.ToXml(DocumentType.Rss)), null, DateTime.Now.AddMinutes(15), TimeSpan.Zero);
}

XDocument rssXml = (XDocument)Cache.Get(RssUrl);


In this examle I add the RSSFeed content as object in the cache and use the url of the RSS feed as Key. The Cache will expire (and cleared) after 15 minutes.

 

Tags: , ,

ASP.Net

Convert XmlElement to XElement (Extension Method)

by Pieter Brinkman 8. December 2008 05:31

I was using some web-services that returned there values in an XmlElement. I needed to convert this XmlElement to something that I can use with LINQ. I didn't find good solutions on the internet. So I started building my own convert logic. After all kinds of solutions I ended up with creating an new XmlDocument, adding the XmlElement to the XmlDocument and then convert the innerXml of the XmlDocument to an XElement. Not really nice but it does the trick.

I've rewritten the code into a Extension Method for the XmlElement.

public static XElement ToXElement(this XmlElement xml)
{
   XmlDocument doc = new XmlDocument();

   doc.AppendChild(doc.ImportNode(xml, true));

   return XElement.Parse(doc.InnerXml);

}


You use the Extension Method like this:

XmlElement xmlElement = wsClient.DoWebServiceRequest();
XElement xml = xmlElement.ToXElement();


Please tell me if you have a better way of doing this!

Cheers,
Pieter

Tags: , , , , , , ,

Linq | XML

Powered by BlogEngine.NET 1.5.0.7
Theme by Mads Kristensen

About Me

My name is Pieter Brinkman I am a .NET Software Engineer for Achmea IT in De Meern, The Netherlands. My interests are mainly web applications created with ASP.NET, MSSQL and Silverlight.

Calendar

<<  September 2010  >>
MoTuWeThFrSaSu
303112345
6789101112
13141516171819
20212223242526
27282930123
45678910

View posts in large calendar

RecentComments

Comment RSS

Most comments

club penguin cheats club penguin cheats
4 comments
us United States
Web Design Company Web Design Company
2 comments
Web design Web design
2 comments
gb United Kingdom