Team LiB
Previous Section Next Section

Loading an XML Document

Finally, you can load an XML document by declaring a new XmlDataDocument and specifying the data. The following example demonstrates loading and displaying an XML document.

Code Example: Loading an XML Document
Start example
using System;
using System.IO;
using System.Xml;

namespace Client.Chapter_22___XML
{
          public class LoadXmlDocumentSample
          {
                 private const String document = "books.xml";
                 public static void Main()
                 {
                       LoadXmlDocumentSample myLoadXmlDocumentSample =
                          new LoadXmlDocumentSample();
                       myLoadXmlDocumentSample.Run(document);
                 }
                 public void Run(String args)
                 {
                        try
                        {
                            //Load the XML from file
                            Console.WriteLine();
                            Console.WriteLine("Loading file {0} ...", args);
                           XmlDataDocument myXmlDocument = new XmlDataDocument();
                            myXmlDocument.Load(args);
                            Console.WriteLine("XmlDataDocument loaded" +
                            "with XML data successfully ...");
                            //Display the XML document
                            myXmlDocument.Save(Console.Out);
                        }
                        catch (Exception e)
                        {
                              Console.WriteLine("Exception: {0}", e.ToString());
                        }
                 }
          }
}
End example

Team LiB
Previous Section Next Section