topical media & game development

talk show tell print

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



  using System;
  using System.Collections.Generic;
  using System.Text;
  using System.Xml;
  using System.Xml.Serialization;
  using System.IO;
  
  namespace XmlSerializationProject
  {
      class Program
      {
          static void Main(string[] args)
          
          {
              try
              {
                  XmlSerializer classSerialization =
                      new XmlSerializer(typeof(StockOrder));
  
                  StockOrder so = new StockOrder();
                  so.Symbol = "MSFT";
                  so.Quantity = 100;
  
                  XmlWriterSettings settings = new XmlWriterSettings();
                  settings.CheckCharacters = true;
                  settings.Encoding = Encoding.Unicode;
                  settings.Indent = true;
  
                  XmlWriter xw = XmlWriter.Create("C:/MyXml.xml", settings);
  
                  classSerialization.Serialize(xw, so);
                  xw.Close();
  
                  Console.Write("Written to disk");
                  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.