To Examples
XmlToConsole Example, source code file Program.cs
using System; using System.Text; using System.Xml; using System.Net; using System.IO; // XmlToConsole Example // Show node names and text for XML files on the internet. namespace RssFeed { public class Program { public static void Main() { WebRequest request = WebRequest.Create("http://condor.depaul.edu/sjost"); // XML generated by an RSS feed. // WebRequest request = // WebRequest.Create("http://dir.yahoo.com/rss/dir/getrss.php?science"); WebResponse response = request.GetResponse(); //Get the Response Stream from the URL Stream responseStream = response.GetResponseStream(); // Read the Response Stream using XmlTextReader XmlTextReader reader = new XmlTextReader(responseStream); reader.WhitespaceHandling = WhitespaceHandling.None; // Output information from nodes. while (reader.Read()) { if (reader.NodeType == XmlNodeType.Element) { Console.WriteLine("Node name: {0}", reader.Name); } else if (reader.NodeType == XmlNodeType.Text) { Console.WriteLine(reader.Value); } } Console.ReadLine(); } } }