Advertisement
ssuther

Program.cs

Feb 11th, 2013
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.52 KB | None | 0 0
  1. using System;
  2. using System.Xml;
  3. using System.Xml.Serialization;
  4. using System.IO;
  5. using System.Data;
  6.  
  7. namespace ReadingXMLDummy
  8. {
  9.     class Program
  10.     {
  11.         static void Main(string[] args)
  12.         {
  13.             ProductEnvironment currentEnvironment;
  14.             currentEnvironment = GetEnvironment(@"ProductEnvironment.xml");
  15.             Console.ReadKey();
  16.         }
  17.  
  18.         public static ProductEnvironment GetEnvironment(string filename)
  19.         {
  20.             XmlSerializer serializer = new XmlSerializer(typeof(ProductEnvironment));
  21.             serializer.UnknownNode += new
  22.             XmlNodeEventHandler(serializer_UnknownNode);
  23.             serializer.UnknownAttribute += new
  24.             XmlAttributeEventHandler(serializer_UnknownAttribute);
  25.  
  26.             ProductEnvironment tempEnvironment;
  27.             using (Stream fileStream = File.Open(filename, FileMode.Open))
  28.             {
  29.                 tempEnvironment = (ProductEnvironment)serializer.Deserialize(fileStream);
  30.             }
  31.             return tempEnvironment;
  32.         }
  33.  
  34.         protected static void serializer_UnknownNode(object sender, XmlNodeEventArgs e)
  35.         {
  36.             Console.WriteLine("Unknown Node:" + e.Name + "\t" + e.Text);
  37.         }
  38.  
  39.         protected static void serializer_UnknownAttribute
  40.         (object sender, XmlAttributeEventArgs e)
  41.         {
  42.             System.Xml.XmlAttribute attr = e.Attr;
  43.             Console.WriteLine("Unknown attribute " +
  44.             attr.Name + "='" + attr.Value + "'");
  45.         }
  46.     }
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement