Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/32.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将图像添加到asp.net rss源_Asp.net_Rss - Fatal编程技术网

如何将图像添加到asp.net rss源

如何将图像添加到asp.net rss源,asp.net,rss,Asp.net,Rss,我不熟悉asp.net中的rss提要,但我很快就掌握了在c#中修改xml的方法。我想在rss2.0中添加一个图像。谢谢你的帮助 Response.Clear(); Response.ContentType = "text/xml"; XmlTextWriter xtwFeed = new XmlTextWriter(Response.OutputStream, Encoding.UTF8); xtwFeed.WriteStartDocumen

我不熟悉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 != "")
            {
编辑说明:我现在有了正确的格式,但图像没有显示出来

 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();
            }
试试这个:

xtwFeed.WriteStartElement("enclosure");
 xtwFeed.WriteElementString("url", blog.PictureURL);
 xtwFeed.WriteElementString("type", image/jpeg);
 xtwFeed.WriteEndElement();
i、 e.您必须将此元素添加到rss xml中

<enclosure url="[PictureURL]" type="image/jpeg"></enclosure>

您可以添加代码的当前输出(rss/xml)吗?这不是我想要做的,我只是希望显示图像,而不是添加要下载的媒体项。谢谢
<enclosure url="[PictureURL]" type="image/jpeg"></enclosure>