/**
* RSS Discovery of Universal Subscription Mechanism
* http://www.kbcafe.com/rss/usm.html
* Author: Randy Charles Morin - http://www.kbcafe.com
* No warranty. Public domain. Attribution appreciated.
**/
using System;
namespace kb.rss
{
///
/// Summary description for Discovery.
///
public class Discovery
{
public static string AutoDiscoverRss(string url)
{
return AutoDiscover(url, "application/rss+xml");
}
public static string AutoDiscoverAtom(string url)
{
return AutoDiscover(url, "application/atom+xml");
}
public static string AutoDiscover(string url, string type)
{
System.Net.WebRequest request = System.Net.WebRequest.Create(url);
request.Timeout = 10000;
System.Net.WebResponse response = request.GetResponse();
System.IO.StreamReader reader = new System.IO.StreamReader(response.GetResponseStream());
string s = reader.ReadToEnd();
while(true)
{
string t = s.ToLower();
int i = t.IndexOf("", i);
if (j == -1)
{
break;
}
string link = s.Substring(i, j-i);
if (link.Substring(link.Length-1,1) == "/")
{
link += ">";
}
else
{
link += "/>";
}
System.Xml.XmlDocument doc = new System.Xml.XmlDocument();
doc.LoadXml(link);
if ( ( doc.DocumentElement.GetAttribute("rel").ToLower() == "alternate" ) &&
( doc.DocumentElement.GetAttribute("type") == type ) )
{
return doc.DocumentElement.GetAttribute("href");
}
s = s.Substring(j);
}
return null;
}
}
}