如何将图像添加到asp.net rss feed
我对 ASP.NET 中的 RSS 提要很陌生,但我很快就掌握了在 C# 中修改 xml 的方法。我想向 rss2.0 添加图像。感谢您的任何帮助。
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", "The Latest goole RSS Feeds. Subscribe Today.");
xtwFeed.WriteElementString("link", "http://googel.com");
xtwFeed.WriteElementString("image", "http://google.com");
xtwFeed.WriteElementString("description", "Click on the title to leave a comment.");
xtwFeed.WriteElementString("copyright", "Copyright 2011 google.com. All rights reserved.");
List<Blog> blogs = (List<Blog>) Blog.GetBlogs();
foreach (var blog in blogs)
{
xtwFeed.WriteStartElement("item");
xtwFeed.WriteElementString("title", blog.Title);
xtwFeed.WriteElementString("link",blog.BlogURL);
if(blog.PictureURL != null || blog.PictureURL != "")
{
//想在这里添加图像 xtwFeed.WriteElementString("图片", blog.PictureURL);
}
xtwFeed.WriteElementString("description", blog.OutputMessage);
xtwFeed.WriteElementString("copyright", "Copyright 2011 google.com. All rights reserved.");
xtwFeed.WriteEndElement();
}
xtwFeed.WriteEndElement();
xtwFeed.WriteEndElement();
xtwFeed.WriteEndDocument();
xtwFeed.Flush();
xtwFeed.Close();
Response.End();
编辑注意:我现在有了正确的格式,但图像没有显示
if(!string.IsNullOrEmpty(blog.PictureURL))
{
xtwFeed.WriteStartElement("image");
xtwFeed.WriteElementString("url", blog.PictureURL);
xtwFeed.WriteElementString("title", blog.Title);
xtwFeed.WriteElementString("link", blog.BlogURL);
xtwFeed.WriteEndElement();
}
I am new to rss feeds in asp.net, but I caught on pretty fast on modifying xml in c#. I want to add a image to the rss2.0. Thanks for any help.
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", "The Latest goole RSS Feeds. Subscribe Today.");
xtwFeed.WriteElementString("link", "http://googel.com");
xtwFeed.WriteElementString("image", "http://google.com");
xtwFeed.WriteElementString("description", "Click on the title to leave a comment.");
xtwFeed.WriteElementString("copyright", "Copyright 2011 google.com. All rights reserved.");
List<Blog> blogs = (List<Blog>) Blog.GetBlogs();
foreach (var blog in blogs)
{
xtwFeed.WriteStartElement("item");
xtwFeed.WriteElementString("title", blog.Title);
xtwFeed.WriteElementString("link",blog.BlogURL);
if(blog.PictureURL != null || blog.PictureURL != "")
{
//WANT TO ADD IMAGE HERE
xtwFeed.WriteElementString("image", blog.PictureURL);
}
xtwFeed.WriteElementString("description", blog.OutputMessage);
xtwFeed.WriteElementString("copyright", "Copyright 2011 google.com. All rights reserved.");
xtwFeed.WriteEndElement();
}
xtwFeed.WriteEndElement();
xtwFeed.WriteEndElement();
xtwFeed.WriteEndDocument();
xtwFeed.Flush();
xtwFeed.Close();
Response.End();
Edit Note: I now have the right format but the image are not showing up
if(!string.IsNullOrEmpty(blog.PictureURL))
{
xtwFeed.WriteStartElement("image");
xtwFeed.WriteElementString("url", blog.PictureURL);
xtwFeed.WriteElementString("title", blog.Title);
xtwFeed.WriteElementString("link", blog.BlogURL);
xtwFeed.WriteEndElement();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
即你必须将此元素添加到 rss xml
Try this:
i.e. you have to add this element to rss xml