topical media & game development

talk show tell print

professional-xml-15-Listing-15-16.txt / txt



  using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Xml;
  using System.IO;
  
  namespace XmlProject
  {
      class Program
      {
          static void Main(string[] args)
          
          {
              try
              {
                  XmlReaderSettings settings = new XmlReaderSettings();
                  settings.IgnoreWhitespace = true;
                  settings.IgnoreComments = true;
                  settings.CheckCharacters = true;
  
                  FileStream myStockOrders = new 
                     FileStream("C:/MyXml.xml", FileMode.Open);
  
                  XmlReader xr = XmlReader.Create(myStockOrders, settings);
  
                  while (xr.Read())
                  {
                      if (xr.NodeType == XmlNodeType.Element &&
                          "Symbol" == xr.LocalName)
                      {
                          Console.WriteLine(xr.Name + " " + 
                             xr.ReadElementContentAsString());
                      }
                  }
  
                  xr.Close();
  
                  Console.WriteLine("Done");
                  Console.ReadLine();
              }
              catch (System.Exception ex)
              {
                  Console.Error.WriteLine(ex.ToString());
                  Console.ReadLine();
              }
          }
      }
  }
  


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.