如何在代码后面添加图像到Rss?

时间:2010-09-27 22:42:51

标签: c# image rss

XmlTextWriter xmlRSS = new XmlTextWriter(Response.OutputStream, Encoding.UTF8);

Other codes...

List<RssItem> rssContents = new List<RssItem>();

get rssContents data ....

foreach (RssItem item in rssContents)

{

  xmlRSS.WriteStartElement("item");

  xmlRSS.WriteElementString("title", item.Title);

  //How can i add image element here...

  xmlRSS.WriteElementString("description", item.Description);

  xmlRSS.WriteElementString("link", item.Link);

  xmlRSS.WriteElementString("pubDate", item.PublishDate);

  xmlRSS.WriteEndElement();

}

 xmlRSS.WriteEndElement();

 xmlRSS.WriteEndElement();

 xmlRSS.WriteEndDocument();

 xmlRSS.Flush();

 xmlRSS.Close();

 Response.End();

1 个答案:

答案 0 :(得分:4)

xmlRss.WriteElementString(“image”,“imagedata”);

编辑:确定使用内置的联合支持。

            var feed = new SyndicationFeed();

        var items = new List<SyndicationItem>();

        foreach (var item in rssItems)
        {
            var syndicationItem = new SyndicationItem
            {
                Title = item.Title,
                Content = item.Description,
                PublishDate = item.PublishDate,

            };

            syndicationItem.ElementExtensions.Add(new XElement("image", item.Image));
            syndicationItem.AddPermalink(new Uri(item.Link));

            items.Add(syndicationItem);
        }

        feed.Items = items;

        using (var xml = new XmlTextWriter(Response.OutputStream, Encoding.UTF8))
        {
            feed.SaveAsRss20(xml);
        }