I have XML writer function:
I am then using ashx to call method:
Works fine, but appends "System.Xml.XmlTextWriter" to the end of my xml.
What am I doing wrong?
Code:
public XmlTextWriter BuildFeed(RssItemCollection collection)
{
XmlTextWriter xml = new XmlTextWriter(HttpContext.Current.Response.OutputStream, Encoding.UTF8);
xml.WriteStartDocument();
xml.WriteStartElement("rss");
xml.WriteAttributeString("version", "2.0");
xml.WriteStartElement("channel");
xml.WriteElementString("title", "title");
xml.WriteElementString("link", "link");
xml.WriteElementString("description", "description.");
foreach (RssItem item in collection)
{
xml.WriteStartElement("item");
xml.WriteElementString("title", item.RssTitle);
xml.WriteElementString("description", item.RssTitle);
xml.WriteElementString("link", item.RssTitle);
xml.WriteElementString("pubDate", item.RssPubDate.ToString("R"));
xml.WriteEndElement();
}
xml.WriteEndElement();
xml.WriteEndElement();
xml.WriteEndDocument();
xml.Flush();
xml.Close();
return xml;
}
I am then using ashx to call method:
public void ProcessRequest(HttpContext context)
{
context.Response.Clear();
RssItem item = new RssItem();
item.RssDescription = "description";
item.RssGuid = "newguid";
item.RssPubDate = DateTime.Now;
item.RssTitle = "title";
RssItemCollection rsscollection = new RssItemCollection();
rsscollection.Add(item);
RssManager manager = new RssManager();
context.Response.ContentType = "text/xml";
context.Response.Write((manager.BuildFeed(rsscollection)).);
context.Response.End();
}
public bool IsReusable
{
get
{
return false;
}
}
Works fine, but appends "System.Xml.XmlTextWriter" to the end of my xml.
What am I doing wrong?