<%@ WebHandler Language="C#" Class="RssHandler" %>
using System;
using System.Web;
using System.Data.Common;
using System.Configuration;
using System.Data;
using System.Xml;
public class RssHandler : IHttpHandler
{
bool IHttpHandler.IsReusable
{
get {return false;}
}
DbDataReader GetDataReader()
{
ConnectionStringSettings cssettings =
ConfigurationManager.ConnectionStrings["nardidbConnectionString"];
DbProviderFactory provider =
DbProviderFactories.GetFactory(cssettings.ProviderName);
DbConnection konekcija = provider.CreateConnection();
konekcija.ConnectionString = cssettings.ConnectionString;
DbCommand komanda = provider.CreateCommand();
komanda.Connection = konekcija;
komanda.CommandText = "Select * From chlanci";
konekcija.Open();
return komanda.ExecuteReader(CommandBehavior.CloseConnection);
}
void IHttpHandler.ProcessRequest(HttpContext context)
{
DbDataReader reader = GetDataReader();
XmlWriterSettings settings = new XmlWriterSettings();
settings.Indent = true;
context.Response.ContentType = "text/xml";
using (XmlWriter writer = XmlWriter.Create(context.Response.OutputStream, settings))
{
writer.WriteStartDocument();
writer.WriteStartElement("rss");
writer.WriteAttributeString("version", "2.0");
writer.WriteStartElement("channel");
writer.WriteElementString("title", "Nove vijesti od Nardi Hrvatska");
writer.WriteElementString("link", "http://www.nardi.com.hr");
writer.WriteElementString("description", "Lista novih Ĩlanaka");
while (reader.Read())
{
writer.WriteStartElement("item");
writer.WriteElementString("title", (string)reader["kratko"]);
writer.WriteElementString("description", (string)reader["tekst"]);
writer.WriteElementString("link", "http://localhost:8780/web/Default.aspx");
writer.WriteEndElement();
}
writer.WriteEndElement();
writer.WriteEndElement();
}
}
Above code retrive RSS data from SQL data store.
}