Read a Brainyquote and parse the value using xpath in .NET

using System;
using System.Net;
using System.Xml;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            using (WebClient wc = new WebClient())
            {
                string data = 
                    wc.DownloadString("https://www.brainyquote.com/link/quotebr.rss");
                XmlDocument xml = new XmlDocument();
                xml.LoadXml(data);
                var node = xml.SelectNodes("//rss/channel/item[1]");

                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("{0} by {1}",
                    node[0]["description"].InnerText,
                    node[0]["title"].InnerText
                    );

                Console.ResetColor();
            }
        }
    }
}

Leave a Reply