首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何向asp.net rss源添加图像

如何向asp.net rss源添加图像
EN

Stack Overflow用户
提问于 2011-08-08 00:12:48
回答 1查看 2.1K关注 0票数 2

我是asp.net中的rss的新手,但在c#中修改XML时我很快就学会了。我想在rss2.0中添加一个镜像。谢谢你的帮助。

代码语言:javascript
复制
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(" IMAGE ",blog.PictureURL);

代码语言:javascript
复制
            }
            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();

编辑注意:我现在有了正确的格式,但图像没有显示出来

代码语言:javascript
复制
 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();
            }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-08-08 04:14:35

试试这个:

代码语言:javascript
复制
xtwFeed.WriteStartElement("enclosure");
 xtwFeed.WriteElementString("url", blog.PictureURL);
 xtwFeed.WriteElementString("type", image/jpeg);
 xtwFeed.WriteEndElement();

也就是说,您必须将此元素添加到rss xml

代码语言:javascript
复制
<enclosure url="[PictureURL]" type="image/jpeg"></enclosure>
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6973959

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档