XmlTypeAttribute 생성자
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
XmlTypeAttribute 클래스의 새 인스턴스를 초기화합니다.
오버로드
XmlTypeAttribute() |
XmlTypeAttribute 클래스의 새 인스턴스를 초기화합니다. |
XmlTypeAttribute(String) |
XmlTypeAttribute 클래스의 새 인스턴스를 초기화하고 XML 형식의 이름을 지정합니다. |
XmlTypeAttribute()
XmlTypeAttribute 클래스의 새 인스턴스를 초기화합니다.
public:
XmlTypeAttribute();
public XmlTypeAttribute ();
Public Sub New ()
예제
다음 예제에서는 두 클래스의 serialization을 재정의 XmlTypeAttribute 하는 데 사용되는 클래스의 두 인스턴스를 만듭니다.
#using <System.Xml.dll>
#using <System.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;
public ref class Address
{
public:
String^ state;
String^ zip;
};
public ref class Person
{
public:
String^ personName;
Address^ address;
};
public ref class PersonTypeAttribute
{
public:
XmlSerializer^ CreateOverrider()
{
XmlAttributeOverrides^ personOverride = gcnew XmlAttributeOverrides;
XmlAttributes^ personAttributes = gcnew XmlAttributes;
XmlTypeAttribute^ personType = gcnew XmlTypeAttribute;
personType->TypeName = "Employee";
personType->Namespace = "http://www.microsoft.com";
personAttributes->XmlType = personType;
XmlAttributes^ addressAttributes = gcnew XmlAttributes;
// Create 'XmlTypeAttribute' with 'TypeName' as an argument.
XmlTypeAttribute^ addressType = gcnew XmlTypeAttribute( "Address" );
addressType->Namespace = "http://www.microsoft.com";
addressAttributes->XmlType = addressType;
personOverride->Add( Person::typeid, personAttributes );
personOverride->Add( Address::typeid, addressAttributes );
XmlSerializer^ myXmlSerializer = gcnew XmlSerializer( Person::typeid,personOverride );
return myXmlSerializer;
}
void SerializeObject( String^ filename )
{
XmlSerializer^ myXmlSerializer = CreateOverrider();
Address^ myAddress = gcnew Address;
myAddress->state = "AAA";
myAddress->zip = "11111";
Person^ myPerson = gcnew Person;
myPerson->personName = "Smith";
myPerson->address = myAddress;
// Serialize to a file.
TextWriter^ writer = gcnew StreamWriter( filename );
myXmlSerializer->Serialize( writer, myPerson );
}
};
int main()
{
PersonTypeAttribute^ myPersonTypeAttribute = gcnew PersonTypeAttribute;
myPersonTypeAttribute->SerializeObject( "XmlType.xml" );
}
using System;
using System.IO;
using System.Xml.Serialization;
public class Person
{
public string personName;
public Address address;
}
public class Address
{
public string state;
public string zip;
}
public class PersonTypeAttribute
{
public static void Main()
{
PersonTypeAttribute myPersonTypeAttribute= new PersonTypeAttribute();
myPersonTypeAttribute.SerializeObject("XmlType.xml");
}
public XmlSerializer CreateOverrider()
{
XmlAttributeOverrides personOverride = new XmlAttributeOverrides();
XmlAttributes personAttributes = new XmlAttributes();
XmlTypeAttribute personType = new XmlTypeAttribute();
personType.TypeName = "Employee";
personType.Namespace = "http://www.microsoft.com";
personAttributes.XmlType = personType;
XmlAttributes addressAttributes = new XmlAttributes();
// Create 'XmlTypeAttribute' with 'TypeName' as an argument.
XmlTypeAttribute addressType = new XmlTypeAttribute("Address");
addressType.Namespace = "http://www.microsoft.com";
addressAttributes.XmlType=addressType;
personOverride.Add(typeof(Person) ,personAttributes);
personOverride.Add(typeof(Address),addressAttributes);
XmlSerializer myXmlSerializer = new XmlSerializer
(typeof(Person), personOverride);
return myXmlSerializer;
}
public void SerializeObject(string filename)
{
XmlSerializer myXmlSerializer = CreateOverrider();
Address myAddress = new Address();
myAddress.state="AAA";
myAddress.zip="11111";
Person myPerson = new Person();
myPerson.personName="Smith";
myPerson.address=myAddress;
// Serialize to a file.
TextWriter writer = new StreamWriter(filename);
myXmlSerializer.Serialize(writer, myPerson);
}
}
Imports System.IO
Imports System.Xml.Serialization
Public Class Person
Public personName As String
Public address As Address
End Class
Public Class Address
Public state As String
Public zip As String
End Class
Public Class PersonTypeAttribute
Public Shared Sub Main()
Dim myPersonTypeAttribute As New PersonTypeAttribute()
myPersonTypeAttribute.SerializeObject("XmlType.xml")
End Sub
Public Function CreateOverrider() As XmlSerializer
Dim personOverride As New XmlAttributeOverrides()
Dim personAttributes As New XmlAttributes()
Dim personType As New XmlTypeAttribute()
personType.TypeName = "Employee"
personType.Namespace = "http://www.microsoft.com"
personAttributes.XmlType = personType
Dim addressAttributes As New XmlAttributes()
' Create 'XmlTypeAttribute' with 'TypeName' as an argument.
Dim addressType As New XmlTypeAttribute("Address")
addressType.Namespace = "http://www.microsoft.com"
addressAttributes.XmlType = addressType
personOverride.Add(GetType(Person), personAttributes)
personOverride.Add(GetType(Address), addressAttributes)
Dim myXmlSerializer As New XmlSerializer(GetType(Person), personOverride)
Return myXmlSerializer
End Function
Public Sub SerializeObject(filename As String)
Dim myXmlSerializer As XmlSerializer = CreateOverrider()
Dim myAddress As New Address()
myAddress.state = "AAA"
myAddress.zip = "11111"
Dim myPerson As New Person()
myPerson.personName = "Smith"
myPerson.address = myAddress
' Serialize to a file.
Dim writer = New StreamWriter(filename)
myXmlSerializer.Serialize(writer, myPerson)
End Sub
End Class
적용 대상
XmlTypeAttribute(String)
XmlTypeAttribute 클래스의 새 인스턴스를 초기화하고 XML 형식의 이름을 지정합니다.
public:
XmlTypeAttribute(System::String ^ typeName);
public XmlTypeAttribute (string typeName);
public XmlTypeAttribute (string? typeName);
new System.Xml.Serialization.XmlTypeAttribute : string -> System.Xml.Serialization.XmlTypeAttribute
Public Sub New (typeName As String)
매개 변수
- typeName
- String
XmlSerializer가 클래스 인스턴스를 직렬화할 때 생성하고 클래스 인스턴스를 역직렬화할 때 인식하는 XML 형식의 이름입니다.
예제
다음 예제에서는 두 클래스의 serialization을 재정의 XmlTypeAttribute 하는 데 사용되는 클래스의 두 인스턴스를 만듭니다.
#using <System.Xml.dll>
#using <System.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;
public ref class Address
{
public:
String^ state;
String^ zip;
};
public ref class Person
{
public:
String^ personName;
Address^ address;
};
public ref class PersonTypeAttribute
{
public:
XmlSerializer^ CreateOverrider()
{
XmlAttributeOverrides^ personOverride = gcnew XmlAttributeOverrides;
XmlAttributes^ personAttributes = gcnew XmlAttributes;
XmlTypeAttribute^ personType = gcnew XmlTypeAttribute;
personType->TypeName = "Employee";
personType->Namespace = "http://www.microsoft.com";
personAttributes->XmlType = personType;
XmlAttributes^ addressAttributes = gcnew XmlAttributes;
// Create 'XmlTypeAttribute' with 'TypeName' as an argument.
XmlTypeAttribute^ addressType = gcnew XmlTypeAttribute( "Address" );
addressType->Namespace = "http://www.microsoft.com";
addressAttributes->XmlType = addressType;
personOverride->Add( Person::typeid, personAttributes );
personOverride->Add( Address::typeid, addressAttributes );
XmlSerializer^ myXmlSerializer = gcnew XmlSerializer( Person::typeid,personOverride );
return myXmlSerializer;
}
void SerializeObject( String^ filename )
{
XmlSerializer^ myXmlSerializer = CreateOverrider();
Address^ myAddress = gcnew Address;
myAddress->state = "AAA";
myAddress->zip = "11111";
Person^ myPerson = gcnew Person;
myPerson->personName = "Smith";
myPerson->address = myAddress;
// Serialize to a file.
TextWriter^ writer = gcnew StreamWriter( filename );
myXmlSerializer->Serialize( writer, myPerson );
}
};
int main()
{
PersonTypeAttribute^ myPersonTypeAttribute = gcnew PersonTypeAttribute;
myPersonTypeAttribute->SerializeObject( "XmlType.xml" );
}
using System;
using System.IO;
using System.Xml.Serialization;
public class Person
{
public string personName;
public Address address;
}
public class Address
{
public string state;
public string zip;
}
public class PersonTypeAttribute
{
public static void Main()
{
PersonTypeAttribute myPersonTypeAttribute= new PersonTypeAttribute();
myPersonTypeAttribute.SerializeObject("XmlType.xml");
}
public XmlSerializer CreateOverrider()
{
XmlAttributeOverrides personOverride = new XmlAttributeOverrides();
XmlAttributes personAttributes = new XmlAttributes();
XmlTypeAttribute personType = new XmlTypeAttribute();
personType.TypeName = "Employee";
personType.Namespace = "http://www.microsoft.com";
personAttributes.XmlType = personType;
XmlAttributes addressAttributes = new XmlAttributes();
// Create 'XmlTypeAttribute' with 'TypeName' as an argument.
XmlTypeAttribute addressType = new XmlTypeAttribute("Address");
addressType.Namespace = "http://www.microsoft.com";
addressAttributes.XmlType=addressType;
personOverride.Add(typeof(Person) ,personAttributes);
personOverride.Add(typeof(Address),addressAttributes);
XmlSerializer myXmlSerializer = new XmlSerializer
(typeof(Person), personOverride);
return myXmlSerializer;
}
public void SerializeObject(string filename)
{
XmlSerializer myXmlSerializer = CreateOverrider();
Address myAddress = new Address();
myAddress.state="AAA";
myAddress.zip="11111";
Person myPerson = new Person();
myPerson.personName="Smith";
myPerson.address=myAddress;
// Serialize to a file.
TextWriter writer = new StreamWriter(filename);
myXmlSerializer.Serialize(writer, myPerson);
}
}
Imports System.IO
Imports System.Xml.Serialization
Public Class Person
Public personName As String
Public address As Address
End Class
Public Class Address
Public state As String
Public zip As String
End Class
Public Class PersonTypeAttribute
Public Shared Sub Main()
Dim myPersonTypeAttribute As New PersonTypeAttribute()
myPersonTypeAttribute.SerializeObject("XmlType.xml")
End Sub
Public Function CreateOverrider() As XmlSerializer
Dim personOverride As New XmlAttributeOverrides()
Dim personAttributes As New XmlAttributes()
Dim personType As New XmlTypeAttribute()
personType.TypeName = "Employee"
personType.Namespace = "http://www.microsoft.com"
personAttributes.XmlType = personType
Dim addressAttributes As New XmlAttributes()
' Create 'XmlTypeAttribute' with 'TypeName' as an argument.
Dim addressType As New XmlTypeAttribute("Address")
addressType.Namespace = "http://www.microsoft.com"
addressAttributes.XmlType = addressType
personOverride.Add(GetType(Person), personAttributes)
personOverride.Add(GetType(Address), addressAttributes)
Dim myXmlSerializer As New XmlSerializer(GetType(Person), personOverride)
Return myXmlSerializer
End Function
Public Sub SerializeObject(filename As String)
Dim myXmlSerializer As XmlSerializer = CreateOverrider()
Dim myAddress As New Address()
myAddress.state = "AAA"
myAddress.zip = "11111"
Dim myPerson As New Person()
myPerson.personName = "Smith"
myPerson.address = myAddress
' Serialize to a file.
Dim writer = New StreamWriter(filename)
myXmlSerializer.Serialize(writer, myPerson)
End Sub
End Class
설명
클래스에 XmlTypeAttribute 적용하여 XML 형식의 네임스페이스, XML 형식 이름 및 XML 스키마 문서에 형식을 포함할지 여부를 지정합니다. 속성을 설정 하는 결과를 확인 합니다 XmlTypeAttribute 클래스, 실행 파일 또는 DLL로 애플리케이션을 컴파일 및 결과 파일을 전달 합니다 XML 스키마 정의 도구 (Xsd.exe). 도구는 형식 정의를 포함하여 스키마를 작성합니다.