XmlElementEventArgs 클래스
UnknownElement 이벤트에 대한 데이터를 제공합니다.
네임스페이스: System.Xml.Serialization
어셈블리: System.Xml(system.xml.dll)
구문
‘선언
Public Class XmlElementEventArgs
Inherits EventArgs
‘사용 방법
Dim instance As XmlElementEventArgs
public class XmlElementEventArgs : EventArgs
public ref class XmlElementEventArgs : public EventArgs
public class XmlElementEventArgs extends EventArgs
public class XmlElementEventArgs extends EventArgs
설명
이벤트 처리에 대한 자세한 내용은 이벤트 및 대리자과 이벤트 발생시키기를 참조하십시오.
UnknownElement 이벤트는 Deserialize 메서드를 호출하는 경우에만 발생합니다.
예제
다음 예제에서는 UnknownElements.xml 파일에서 Group
클래스를 deserialize합니다. 이 클래스에 해당 멤버가 없는 파일에서 요소가 발견될 때마다 UnknownElement 이벤트가 발생합니다. 이 예제를 실행하려면 다음 XML 코드를 UnknownElements.xml 파일에 붙여넣습니다.
<?xml version="1.0" encoding="utf-8"?>
<Group xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<GroupName>MyGroup</GroupName>
<GroupSize>Large</GroupSize>
<GroupNumber>444</GroupNumber>
<GroupBase>West</GroupBase>
</Group>
Imports System
Imports System.IO
Imports System.Xml.Serialization
Imports System.Xml
Imports System.Xml.Schema
Imports Microsoft.VisualBasic
Public Class Group
Public GroupName As String
End Class
Public Class Test
Shared Sub Main()
Dim t As Test = new Test()
' Deserialize the file containing unknown elements.
t.DeserializeObject("UnknownElements.xml")
End Sub
Private Sub Serializer_UnknownElement _
(sender As Object , e As XmlElementEventArgs)
Console.WriteLine("Unknown Element")
Console.WriteLine(ControlChars.Tab & e.Element.Name + " " & e.Element.InnerXml)
Console.WriteLine(ControlChars.Tab & e.LineNumber & ":" & e.LineNumber)
Console.WriteLine(ControlChars.Tab & e.LinePosition & ":" & e.LinePosition)
Dim x As Group = CType( e.ObjectBeingDeserialized, Group)
Console.WriteLine (x.GroupName)
Console.WriteLine (sender.ToString())
End Sub
Private Sub DeserializeObject(filename As String)
Dim ser As XmlSerializer = new XmlSerializer(GetType(Group))
' Add a delegate to handle unknown element events.
AddHandler ser.UnknownElement, _
AddressOf Serializer_UnknownElement
' A FileStream is needed to read the XML document.
Dim fs As FileStream = new FileStream(filename, FileMode.Open)
Dim g As Group = CType(ser.Deserialize(fs),Group)
fs.Close()
End Sub
End Class
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();
}
}
#using <System.Xml.dll>
#using <System.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;
using namespace System::Xml;
using namespace System::Xml::Schema;
public ref class Group
{
public:
String^ GroupName;
};
public ref class Test
{
private:
void Serializer_UnknownElement( Object^ sender, XmlElementEventArgs^ e )
{
Console::WriteLine( "Unknown Element" );
Console::Write( "\t {0}", e->Element->Name );
Console::WriteLine( " {0}", e->Element->InnerXml );
Console::WriteLine( "\t LineNumber: {0}", e->LineNumber );
Console::WriteLine( "\t LinePosition: {0}", e->LinePosition );
Group^ x = dynamic_cast<Group^>(e->ObjectBeingDeserialized);
Console::WriteLine( x->GroupName );
Console::WriteLine( sender );
}
public:
void DeserializeObject( String^ filename )
{
XmlSerializer^ ser = gcnew XmlSerializer( Group::typeid );
// Add a delegate to handle unknown element events.
ser->UnknownElement += gcnew XmlElementEventHandler( this, &Test::Serializer_UnknownElement );
// A FileStream is needed to read the XML document.
FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
Group^ g = dynamic_cast<Group^>(ser->Deserialize( fs ));
fs->Close();
}
};
int main()
{
Test^ t = gcnew Test;
// Deserialize the file containing unknown elements.
t->DeserializeObject( "UnknownElements.xml" );
}
import System.*;
import System.IO.*;
import System.Xml.Serialization.*;
import System.Xml.*;
import System.Xml.Schema.*;
public class Group
{
public String GroupName;
} //Group
public class Test
{
public static void main(String[] args)
{
Test t = new Test();
// Deserialize the file containing unknown elements.
t.DeserializeObject("UnknownElements.xml");
} //main
private void Serializer_UnknownElement(Object sender,
XmlElementEventArgs e)
{
Console.WriteLine("Unknown Element");
Console.WriteLine("\t" + e.get_Element().get_Name() + " "
+ e.get_Element().get_InnerXml());
Console.WriteLine("\t LineNumber: " + e.get_LineNumber());
Console.WriteLine("\t LinePosition: " + e.get_LinePosition());
Group x = (Group)(e.get_ObjectBeingDeserialized());
Console.WriteLine(x.GroupName);
Console.WriteLine(sender.ToString());
} //Serializer_UnknownElement
private void DeserializeObject(String fileName)
{
XmlSerializer ser = new XmlSerializer(Group.class.ToType());
// Add a delegate to handle unknown element events.
ser.add_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();
} //DeserializeObject
} //Test
상속 계층 구조
System.Object
System.EventArgs
System.Xml.Serialization.XmlElementEventArgs
스레드로부터의 안전성
이 형식의 모든 public static(Visual Basic의 경우 Shared) 멤버는 스레드로부터 안전합니다. 인터페이스 멤버는 스레드로부터 안전하지 않습니다.
플랫폼
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
2.0, 1.1, 1.0에서 지원
.NET Compact Framework
2.0에서 지원