Quantcast
Channel: Visual C# forum
Viewing all articles
Browse latest Browse all 31927

How can i display the cnn rss news feeds ?

$
0
0

I did a new class :

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Net;
using System.Data;
using System.Xml.Linq;
using System.Xml;
using System.IO;

namespace ScrollLabelTest
{
    class RssReader
    {
        public class RssNews
        {
            public string Title;
            public string PublicationDate;
            public string Description;
        }

        public class RssReading
        {
            public static List<RssNews> Read(string url)
            {
                var webClient = new WebClient();
                webClient.Encoding = Encoding.GetEncoding("windows-1255");
                string result = webClient.DownloadString(url);
                XDocument document = XDocument.Parse(result);

                return (from descendant in document.Descendants("item")
                        select new RssNews()
                        {
                            Description = descendant.Element("description").Value,
                            Title = descendant.Element("title").Value,
                            PublicationDate = descendant.Element("pubDate").Value
                        }).ToList();
            }
        }


        public static string covertRss(string url)
        {
            var s = RssReading.Read(url);
            StringBuilder sb = new StringBuilder();
            foreach (RssNews rs in s)
            {
                sb.AppendLine(rs.Title);
                sb.AppendLine(rs.PublicationDate);
                sb.AppendLine(rs.Description);
            }

            return sb.ToString();
        }

        public static void CnnRss()
        {
            HttpWebRequest request =
                HttpWebRequest.Create("http://rss.cnn.com/rss/cnn_topstories") as HttpWebRequest;
            request.Accept = "*/*";
            request.Headers.Add("UA-CPU", "x86");
            request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; MS-RTC LM 8)";

            HttpWebResponse response = request.GetResponse() as HttpWebResponse;
            XmlTextReader readr = new XmlTextReader(response.GetResponseStream());

            //this part is optional, the XmlReader above is what your code can run off
            XmlDocument doc2 = new XmlDocument();
            doc2.Load(readr);
            doc2.Save(@"d:\feed.xml");
        }
    }
}

In the read method im using:

webClient.Encoding = Encoding.GetEncoding("windows-1255");

Since the url im using now is in hebrew.

But now i want to display instead the cnn url of the rss news.

So i added the method CnnRss.

But how do i use it ?

In form1 im using the RssReader class like this:

readableRss = RssReader.covertRss("http://rotter.net/rss/rotternews.xml");
this.scrollLabel1.Text = readableRss;

readableRss is a string.

This is the hebrew url and its working good.

But if im adding the cnn url instead the hebrew one i see the cnn rss but with many symbols and chars that are not text or part of the text of the rss.

I cant use the covertRss method with the url of the cnn. 

I need something else or some other way. How can i display the cnn rss feedings ?


Viewing all articles
Browse latest Browse all 31927

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>