本文整理汇总了C#中System.Xml.Serialization.XmlElementEventArgs类的典型用法代码示例。如果您正苦于以下问题:C# XmlElementEventArgs类的具体用法?C# XmlElementEventArgs怎么用?C# XmlElementEventArgs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
XmlElementEventArgs类属于System.Xml.Serialization命名空间,在下文中一共展示了XmlElementEventArgs类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.IO;
using System.Xml.Serialization;
using System.Xml;
using System.Xml.Schema;
public class Group{
public string GroupName;
}
public class Test{
static void Main(){
Test t = new Test();
// Deserialize the file containing unknown elements.
t.DeserializeObject("UnknownElements.xml");
}
private void Serializer_UnknownElement(object sender, XmlElementEventArgs e){
Console.WriteLine("Unknown Element");
Console.WriteLine("\t" + e.Element.Name + " " + e.Element.InnerXml);
Console.WriteLine("\t LineNumber: " + e.LineNumber);
Console.WriteLine("\t LinePosition: " + e.LinePosition);
Group x = (Group) e.ObjectBeingDeserialized;
Console.WriteLine (x.GroupName);
Console.WriteLine (sender.ToString());
}
private void DeserializeObject(string filename){
XmlSerializer ser = new XmlSerializer(typeof(Group));
// Add a delegate to handle unknown element events.
ser.UnknownElement+=new XmlElementEventHandler(Serializer_UnknownElement);
// A FileStream is needed to read the XML document.
FileStream fs = new FileStream(filename, FileMode.Open);
Group g = (Group) ser.Deserialize(fs);
fs.Close();
}
}