Пример #1
0
        //
        // GET: /News/
        public ActionResult Index()
        {
            string url = "http://izmir.edu.tr/izmir-universitesi/%C3%BCniversite-haberler/universite-genel-haberler.feed?type=rss";

            XmlDocument rssXmlDoc = new XmlDocument();

            // Load the RSS file from the RSS URL
            rssXmlDoc.Load(url);

            // Parse the Items in the RSS file
            XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item");

            StringBuilder rssContent = new StringBuilder();
            List<RssNews> rssnewslist = new List<RssNews>();
            // Iterate through the items in the RSS file
            foreach (XmlNode rssNode in rssNodes)
            {
                RssNews rssnew = new RssNews();
                XmlNode rssSubNode = rssNode.SelectSingleNode("title");
                string title = rssSubNode != null ? rssSubNode.InnerText : "";

                rssSubNode = rssNode.SelectSingleNode("link");
                string link = rssSubNode != null ? rssSubNode.InnerText : "";

                rssSubNode = rssNode.SelectSingleNode("description");
                string description = rssSubNode != null ? rssSubNode.InnerText : "";

                rssnew.Title = title;
                rssnew.Link = link;
                rssnew.Description = description;

                rssnewslist.Add(rssnew);
            }

            return View(rssnewslist);
        }
        public List<RssNews> getAnnoucment(string url)
        {
            WebRequest request = WebRequest.Create(url);
            WebResponse response = request.GetResponse();
            Stream dataStream = response.GetResponseStream();

            StreamReader reader = new StreamReader(dataStream);
            string text = reader.ReadToEnd();

            XmlDocument xmlDoc = new XmlDocument();
            text = text.Replace((char)(0x1F), ' ');

            XmlDocument rssXmlDoc = new XmlDocument();

            // Load the RSS file from the RSS URL
            rssXmlDoc.LoadXml(text);

            // Parse the Items in the RSS file
            XmlNodeList rssNodes = rssXmlDoc.SelectNodes("rss/channel/item");

            StringBuilder rssContent = new StringBuilder();
            List<RssNews> rssnewslist = new List<RssNews>();
            // Iterate through the items in the RSS file
            foreach (XmlNode rssNode in rssNodes)
            {
                RssNews rssnew = new RssNews();
                XmlNode rssSubNode = rssNode.SelectSingleNode("title");
                string title = rssSubNode != null ? rssSubNode.InnerText : "";

                rssSubNode = rssNode.SelectSingleNode("link");
                string link = rssSubNode != null ? rssSubNode.InnerText : "";

                rssSubNode = rssNode.SelectSingleNode("description");
                string description = rssSubNode != null ? rssSubNode.InnerText : "";

                rssnew.Title = title;
                rssnew.Link = link;
                rssnew.Description = description;

                rssnewslist.Add(rssnew);
            }

            return rssnewslist;
        }