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} ...

Get .NET Common Language Runtime Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.