-

 - e-mail

 

 -

   Flashr

 -

 LiveInternet.ru:
: 26.02.2007
:
:
: 6574

:


How to RSS your data

, 01 2009 . 00:24 +
RSS - . RSS , , , guid. , RSS , reader.google.com, , 3 - . , - 3 . - " " . , , , , .

RSS ( RssToolKit 2.0 ). CSharp UTF-16, XML , . , , - FireFox, IE8 ( Opera ) - XML, UTF-8 RSS, RssToolKit, :
Copy Source | Copy HTML
  1. /// <summary>
  2. /// Returns XML of the Generic Type.
  3. /// </summary>
  4. /// <param name="rssDocument">The RSS document.</param>
  5. /// <typeparam name="T">RssDocumentBase</typeparam>
  6. /// <returns>string</returns>
  7. public static string ToRssXml<T>(T rssDocument) where T : RssDocumentBase
  8. {
  9.     if (rssDocument == null)
  10.     {
  11.         throw new ArgumentNullException("rssDocument");
  12.     }
  13.  
  14.     MemoryStream memoryStream = new MemoryStream();
  15.     String XmlizedString = null;
  16.     using (XmlTextWriter output = new XmlTextWriter(memoryStream, Encoding.UTF8))
  17.     {
  18.  
  19.         XmlSerializer serializer = new XmlSerializer(typeof(T));
  20.         serializer.Serialize(output, rssDocument);
  21.         memoryStream = (MemoryStream)output.BaseStream;
  22.         XmlizedString = UTF8ByteArrayToString(memoryStream.ToArray());
  23.         return XmlizedString;
  24.     }
  25. }
  26.  
  27. /// <summary>
  28. /// To convert a Byte Array of Unicode values (UTF-8 encoded) to a complete String.
  29. /// </summary>
  30. /// <param name="characters">Unicode Byte Array to be converted to String</param>
  31. /// <returns>String converted from Unicode Byte Array</returns>
  32. private static String UTF8ByteArrayToString(Byte[] characters)
  33. {
  34.     UTF8Encoding encoding = new UTF8Encoding();
  35.     String constructedString = encoding.GetString(characters);
  36.     return (constructedString);
  37. }
RSS asp- :
Copy Source | Copy HTML
  1. //,    XML/RSS
  2. Response.ContentType = "application/rss+xml";
  3. //   
  4. using (MySQL db = new MySQL())
  5. {
  6.     DataSet ds = db.GetData("get_rss");
  7.     if (ds != null && ds.Tables[0].Rows.Count > 0)
  8.     {
  9.         RssDocument rss = new RssDocument()
  10.         {
  11.             Version = "2.0",
  12.             Channel = new RssChannel()
  13.             {
  14.                 LastBuildDate = DateTime.Now.ToString(),
  15.                 Language = "ru-RU",
  16.                 WebMaster = "topbot@ya.ru",
  17.             }
  18.         };
  19.         rss.Channel.Title = "blabla"
  20.         rss.Channel.Link = ds.Tables[0].Rows[0]["linkto"].ToString();
  21.         rss.Channel.Items = new List<RssItem>(0);
  22.         foreach (DataRow dr in ds.Tables[0].Rows)
  23.         {
  24.             RssItem ritem = new RssItem()
  25.             {
  26.                 PubDate = ((DateTime)dr["when"]).ToString("s"),
  27.                 Description = dr["text"].ToString()
  28.             };
  29.             rss.Channel.Items.Add(ritem);
  30.         }
  31.         Response.Write(rss.ToXml(DocumentType.Rss));
  32.     }
  33.     else
  34.     {
  35.         Response.ContentType = "application/rss+xml";
  36.     }
  37.  
  38. }
:  

: [1] []
 

:
: 

: ( )

:

  URL