使用SQL数据源和背后的代码创建mRSS Feed [英] Create a mRSS feed with SQL datasource and code behind
问题描述
你好,
我正在尝试创建媒体Rss feed,以便可以使用cooliris插件查看SQL数据库中的图像.我已经创建了一个标准的rss提要,并且可以正常工作,但是,我在创建cooliris插件查找图像所需的media:content标签时遇到了麻烦.到目前为止,这就是我在代码中所拥有的.如何将media:content标记添加到WriteElementStrings,以便它们将插件显示在我的图像位置?很抱歉,如果我不清楚我要问什么,但随时可以提出任何问题.
提前谢谢...
至于代码:
Hello,
I am trying to create a media Rss feed so that I can use a cooliris plugin to view the images in my SQL database. I have created a standard rss feed and it works, however, I am having trouble creating the media:content tags that the cooliris plugin needs to find the images. This is what I have in my code behind so far. How do I add the media:content tags to WriteElementStrings so that they will show the plugin my image location? Sorry if I am being unclear of what I am asking, but feel free to ask any questions.
Thanks in advance...
As for the code:
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
using System.Text;
using System.Data.SqlClient;
public partial class Pages_MyFeed : System.Web.UI.Page
{
string strConnection = "Data Source=Source;User ID=ID;Password=PWD;";
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
// Clear the response buffer contents
Response.Clear();
Response.ContentType = "text/xml";
XmlTextWriter rssFeed = new XmlTextWriter
(Response.OutputStream, Encoding.UTF8);
//writing RSS tags
rssFeed.WriteStartDocument();
rssFeed.WriteStartElement("rss");
rssFeed.WriteAttributeString("version", "2.0");
rssFeed.WriteAttributeString("xmlns:media", "http://search.yahoo.com/mrss/");
rssFeed.WriteAttributeString("xmlns:atom", "http://www.w3.org/2005/Atom");
rssFeed.WriteStartElement("channel");
rssFeed.WriteElementString("title", "Hat Details");
rssFeed.WriteElementString("description", "Custom Hat Details");
rssFeed.WriteElementString("link", "http://www.myheadpiece.com");
rssFeed.WriteElementString("image", "URL");
// create sql connection and connect to database
SqlConnection con = new SqlConnection(strConnection);
SqlCommand cmd = new SqlCommand();
cmd.CommandType = CommandType.StoredProcedure;
cmd.CommandText = "Find_all";
cmd.Connection = con;
con.Open();
SqlDataReader dReader;
dReader = cmd.ExecuteReader();
while (dReader.Read())
{
string url = "http://www.myheadpiece.com/Images/Hats/" + dReader["URL"] + ".png";
rssFeed.WriteStartElement("item");
rssFeed.WriteElementString("title", dReader["HatName"].ToString());
rssFeed.WriteElementString("description", dReader["HatName"].ToString());
rssFeed.WriteElementString("link", url);
rssFeed.WriteElementString("image", url);
rssFeed.WriteElementString("pubDate", DateTime.Now.ToString());
rssFeed.WriteEndElement();
}
dReader.Close();
con.Close();
rssFeed.WriteEndElement();
rssFeed.WriteEndElement();
rssFeed.WriteEndDocument();
rssFeed.Flush();
rssFeed.Close();
Response.End();
}
}
}
推荐答案
很显然,我的问题没有多大意义,所以我将尽力澄清.
因此,如果您在这里查看我当前的Feed: http://myheadpiece.com/pages/myfeed.aspx [ ^ ]
您可以看到media:content标签.但是,如果您看一下flickr的以下供稿: http://www. flickr.com/services/feeds/photos_public.gne?tags=toy&format=rss_200 [
So obviously my question is not making much sense so I will try to clarify.
So if you take a look at my current feed here: http://myheadpiece.com/pages/myfeed.aspx[^]
You can see the media:content tag. But if you take a look at this feed from flickr: http://www.flickr.com/services/feeds/photos_public.gne?tags=toy&format=rss_200[^]
This feed is in the correct format that my plugin can read. As you can see the media:content tag has additional information within the tag that is different from my feed. Obviously I can accomplish this by writing all of the xml in a static manner, but I want to do this dynamically from my SQL database that I have already created. So my question is this, how can I write my code in my code behind to emulate the media:content tags that are seen in the flickr feed so that my plugin can read my own mRSS feed?
这篇关于使用SQL数据源和背后的代码创建mRSS Feed的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!