O'Reilly logo

.NET Common Language Runtime Unleashed by Kevin Burton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

System.Xml

The model that the .NET Framework uses to read and parse XML files is somewhat of a mix between the traditional COM approach and the SAX approach. Listing B.69 shows how to read in and process an XML file (xmlread.cs). Two sample XML files, booklist.xml and number-list.xml, have also been included.

Listing B.69. Reading an XML File
 public class ReadXmlFile { public static void Main(string [] args) { string document = "booklist.xml"; ReadXmlFile readXml = new ReadXmlFile(); if ( args.Length > 0 ) { foreach(string arg in args) readXml.Process(arg); } else readXml.Process(document); } public void Process(String document) { XmlTextReader reader = null; try { // Load the file with an XmlTextReader. Console.WriteLine ("Reading file {0} ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required