using System.Data.SqlClient;
using System.Text;
using System.Xml;
// Clear any previous output from the buffer
Response.Clear();
Response.ContentType = "text/xml";
XmlTextWriter xtwFeed = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);
xtwFeed.WriteStartDocument();
// The mandatory rss tag
xtwFeed.WriteStartElement("rss");
xtwFeed.WriteAttributeString("version", "2.0");
// The channel tag contains RSS feed details
xtwFeed.WriteStartElement("channel");
xtwFeed.WriteElementString("title", "Feedpedia Today's World News");
xtwFeed.WriteElementString("link", http://amitmetkar.blogspot.com/);
xtwFeed.WriteElementString("description", "The latest news and journals from all over the world.");
xtwFeed.WriteElementString("copyright", "Copyright 2008-09 Amit Merkar All rights reserved.");
// Objects needed for connecting to the SQL database
SqlConnection SqlCon;
SqlCommand SqlCom;
SqlDataReader SqlDR;
// Edit to match your connection string
SqlCon = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
// Edit to match your stored procedure or SQL command
SqlCom = new SqlCommand("GetTodaysHeadlines", SqlCon);
SqlCom.CommandType = CommandType.StoredProcedure;
if (SqlCon.State == ConnectionState.Closed)
{
SqlCon.Open();
}
SqlDR = SqlCom.ExecuteReader();
// Loop through the content of the database and add them to the RSS feed while (SqlDR.Read()){
xtwFeed.WriteStartElement("item");
xtwFeed.WriteElementString("title", SqlDR["Title"].ToString());
xtwFeed.WriteElementString("description", SqlDR["Description"].ToString());
xtwFeed.WriteElementString("link", "http://www.feedpedia.com/View.aspx?View=" + SqlDR["ID"]);
xtwFeed.WriteElementString("pubDate", SqlDR["Date"].ToString());
xtwFeed.WriteEndElement();
}
SqlDR.Close();
SqlCon.Close();
// Close all tags
xtwFeed.WriteEndElement();
xtwFeed.WriteEndElement();
xtwFeed.WriteEndDocument();
xtwFeed.Flush();
xtwFeed.Close();
Response.End();
H1B Interview Sample Questions & Answers
17 years ago
No comments:
Post a Comment