Click here to Skip to main content
14,428,072 members
Rate this:
Please Sign up or sign in to vote.
See more:
protected void Page_Load(object sender, EventArgs e)
        {
            Response.ContentType = "text/xml";
            Response.ContentEncoding = Encoding.UTF8;
            if (Cache["RssFeed"] == null)
            {
               
                ConnectionManager cm = new ConnectionManager();
                cm.Command.CommandText = "select Title,TitleSimplified,ImageMainURL,URL,Description,InsertDate from tblFeedsItems";
                cm.Command.CommandType = CommandType.Text;
                cm.Connection.Open();
                SqlDataReader dr = cm.Command.ExecuteReader();
                DataTable articleData  = new DataTable("articleData");
                articleData.Load(dr);
               
                StringWriter sw = new StringWriter();
                XmlTextWriter writer = new XmlTextWriter(sw);

                writer.WriteStartElement("rss");
                writer.WriteAttributeString("version","2.0");

                writer.WriteStartElement("channel");

                writer.WriteElementString("title","Example RSS Title");
                writer.WriteElementString("link","http://example.com/");
                writer.WriteElementString("description","This is a demonstration RSS feed");
                writer.WriteElementString("ttl","60");

                const int RSS_Items = 10;
                for (int i=0; i < RSS_Items; i++)
                {
                    writer.WriteStartElement("item");

                    writer.WriteElementString("Title", articleData.Rows[i]["Title"].ToString());
                    writer.WriteElementString("link", articleData.Rows[i]["URL"].ToString());
                    writer.WriteElementString("description", articleData.Rows[i]["Description"].ToString());
                    writer.WriteElementString("pubDate", (articleData.Rows[i]["InsertDate"].ToString()));

                    writer.WriteEndElement();
                }
                writer.WriteEndElement();

                writer.WriteEndElement();


                Cache.Insert("RssFeed",sw.ToString(),null,DateTime.Now.AddHours(1.5),TimeSpan.Zero);
                writer.Close();
            }

            Response.Write(Cache["RssFeed"].ToString());
        }



and give this error when i Run it :
This page contains the following errors:

error on line 3 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.



plz help me :(
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100