Rssread.cs

From AdonaiMedrado.Pro.Br
Jump to: navigation, search
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Net;
using System.IO;
 
namespace rssread
{
    class Program
    {
        static void Main(string[] args)
        {
            string s;
 
            do
            {
                s = Console.ReadLine();
                if (!string.IsNullOrEmpty(s))
                {
                    DataSet ds = new DataSet();
                    WebClient wc = new WebClient();
                    StringReader sr = new StringReader(wc.DownloadString(s));
 
                    ds.ReadXml(sr);
 
                    Console.WriteLine(ds.Tables["channel"].Rows[0]["title"]); ;
                    for (int i = 0; i < ds.Tables["item"].Rows.Count; i++)
                    {
                        DataRow row = ds.Tables["item"].Rows[i];
                        Console.WriteLine("\t" + i + " " + row["title"]);
                        if (!string.IsNullOrEmpty((string)row["description"]))
                            Console.WriteLine("\t\t" + row["description"]);
                    }
 
                    wc.Dispose();
                    sr.Dispose();
                    ds.Dispose();
                }
            } while (!string.IsNullOrEmpty(s));
        }
    }
}