XmlTypeAttribute クラス
アセンブリ: System.Xml (system.xml.dll 内)

<AttributeUsageAttribute(AttributeTargets.Class Or AttributeTargets.Struct Or AttributeTargets.Enum Or AttributeTargets.Interface)> _ Public Class XmlTypeAttribute Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Class|AttributeTargets.Struct|AttributeTargets.Enum|AttributeTargets.Interface)] public class XmlTypeAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Class|AttributeTargets::Struct|AttributeTargets::Enum|AttributeTargets::Interface)] public ref class XmlTypeAttribute : public Attribute

XmlTypeAttribute は、XmlSerializer がオブジェクトをシリアル化または逆シリアル化する方法を制御する一連の属性の 1 つです。類似する属性の完全な一覧については、「XML シリアル化を制御する属性」を参照してください。
XmlTypeAttribute は、クラス、構造体、列挙体、またはインターフェイスの宣言に適用できます。
XmlTypeAttribute をクラスに適用し、XML 型の名前空間、XML 型名、および XML スキーマ ドキュメントにその型を含めるかどうかを指定します。XmlTypeAttribute クラスのプロパティの設定結果を確認するには、アプリケーションをコンパイルして実行可能ファイルまたは DLL を生成し、生成されたファイルを XML スキーマ定義ツール (Xsd.exe) に渡します。このツールは、型定義を含むスキーマを作成します。
![]() |
---|
IncludeInSchema プロパティを false に設定した場合、XML スキーマ定義ツール (Xsd.exe) は、スキーマにその型を含めません。既定では、各パブリック クラスに対して、XSD ツールは complexType とその型の要素を生成します。 |

XmlTypeAttribute が適用された 2 つのクラスの例を次に示します。
<XmlType(Namespace := "http://www.cpandl.com", _ TypeName := "GroupMember")> _ Public Class Person Public Name As String End Class <XmlType(Namespace := "http://www.cohowinery.com", _ TypeName := "GroupAddress")> _ Public Class Address Public Line1 As String Public Line2 As String Public City As String Public State As String Public Zip As String End Class Public Class Group Public Staff() As Person Public Manager As Person Public Location As Address End Class
[XmlType(Namespace = "http://www.cpandl.com", TypeName = "GroupMember")] public class Person { public string Name; } [XmlType(Namespace = "http://www.cohowinery.com", TypeName = "GroupAddress")] public class Address { public string Line1; public string Line2; public string City; public string State; public string Zip; } public class Group { public Person[] Staff; public Person Manager; public Address Location; }
[XmlType(Namespace="http://www.cpandl.com", TypeName="GroupMember")] public ref class Person { public: String^ Name; }; [XmlType(Namespace="http://www.cohowinery.com", TypeName="GroupAddress")] public ref class Address { public: String^ Line1; String^ Line2; String^ City; String^ State; String^ Zip; }; public ref class Group { public: array<Person^>^Staff; Person^ Manager; Address^ Location; };
/** @attribute XmlType(Namespace = "http://www.cpandl.com" , TypeName = "GroupMember") */ public class Person { public String name; } //Person /** @attribute XmlType(Namespace = "http://www.cohowinery.com" , TypeName = "GroupAddress") */ public class Address { public String line1; public String line2; public String city; public String state; public String zip; } //Address public class Group { public Person staff[]; public Person manager; public Address location; } //Group

System.Attribute
System.Xml.Serialization.XmlTypeAttribute


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlTypeAttribute コンストラクタ ()
アセンブリ: System.Xml (system.xml.dll 内)


XmlTypeAttribute クラスの 2 つのインスタンスを作成し、それらのインスタンスを使用して 2 つのクラスのシリアル化をオーバーライドする例を次に示します。
Imports System 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
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); } }
#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" ); }
import System.*; import System.IO.*; import System.Xml.Serialization.*; public class Person { public String personName; public Address address; } //Person public class Address { public String state; public String zip; } //Address public class PersonTypeAttribute { public static void main(String[] args) { PersonTypeAttribute myPersonTypeAttribute = new PersonTypeAttribute(); myPersonTypeAttribute.SerializeObject("XmlType.xml"); } //main public XmlSerializer CreateOverrider() { XmlAttributeOverrides personOverride = new XmlAttributeOverrides(); XmlAttributes personAttributes = new XmlAttributes(); XmlTypeAttribute personType = new XmlTypeAttribute(); personType.set_TypeName("Employee"); personType.set_Namespace("http://www.microsoft.com"); personAttributes.set_XmlType(personType); XmlAttributes addressAttributes = new XmlAttributes(); // Create 'XmlTypeAttribute' with 'TypeName' as an argument. XmlTypeAttribute addressType = new XmlTypeAttribute("Address"); addressType.set_Namespace("http://www.microsoft.com"); addressAttributes.set_XmlType(addressType); personOverride.Add(Person.class.ToType(), personAttributes); personOverride.Add(Address.class.ToType(), addressAttributes); XmlSerializer myXmlSerializer = new XmlSerializer(Person.class.ToType() , personOverride); return myXmlSerializer; } //CreateOverrider 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); } //SerializeObject } //PersonTypeAttribute

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlTypeAttribute コンストラクタ (String)
アセンブリ: System.Xml (system.xml.dll 内)


XmlTypeAttribute をクラスに適用し、XML 型の名前空間、XML 型名、および XML スキーマ ドキュメントにその型を含めるかどうかを指定します。XmlTypeAttribute クラスのプロパティの設定結果を確認するには、アプリケーションをコンパイルして実行可能ファイルまたは DLL を生成し、生成されたファイルを XML スキーマ定義ツール (Xsd.exe) に渡します。このツールは、型定義を含むスキーマを作成します。

XmlTypeAttribute クラスの 2 つのインスタンスを作成し、それらのインスタンスを使用して 2 つのクラスのシリアル化をオーバーライドする例を次に示します。
Imports System 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
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); } }
#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" ); }
import System.*; import System.IO.*; import System.Xml.Serialization.*; public class Person { public String personName; public Address address; } //Person public class Address { public String state; public String zip; } //Address public class PersonTypeAttribute { public static void main(String[] args) { PersonTypeAttribute myPersonTypeAttribute = new PersonTypeAttribute(); myPersonTypeAttribute.SerializeObject("XmlType.xml"); } //main public XmlSerializer CreateOverrider() { XmlAttributeOverrides personOverride = new XmlAttributeOverrides(); XmlAttributes personAttributes = new XmlAttributes(); XmlTypeAttribute personType = new XmlTypeAttribute(); personType.set_TypeName("Employee"); personType.set_Namespace("http://www.microsoft.com"); personAttributes.set_XmlType(personType); XmlAttributes addressAttributes = new XmlAttributes(); // Create 'XmlTypeAttribute' with 'TypeName' as an argument. XmlTypeAttribute addressType = new XmlTypeAttribute("Address"); addressType.set_Namespace("http://www.microsoft.com"); addressAttributes.set_XmlType(addressType); personOverride.Add(Person.class.ToType(), personAttributes); personOverride.Add(Address.class.ToType(), addressAttributes); XmlSerializer myXmlSerializer = new XmlSerializer(Person.class.ToType() , personOverride); return myXmlSerializer; } //CreateOverrider 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); } //SerializeObject } //PersonTypeAttribute

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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


XmlTypeAttribute コンストラクタ

名前 | 説明 |
---|---|
XmlTypeAttribute () | XmlTypeAttribute クラスの新しいインスタンスを初期化します。 .NET Compact Framework によってサポートされています。 |
XmlTypeAttribute (String) | XmlTypeAttribute クラスの新しいインスタンスを初期化し、XML 型の名前を指定します。 .NET Compact Framework によってサポートされています。 |

XmlTypeAttribute プロパティ

名前 | 説明 | |
---|---|---|
![]() ![]() ![]() ![]() | TypeId | 派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。 ( Attribute から継承されます。) |
![]() | TypeName | XML 型の名前を取得または設定します。 |

XmlTypeAttribute メソッド

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 ( Attribute から継承されます。) |
![]() | GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 ( Attribute から継承されます。) |
![]() | GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 ( Attribute から継承されます。) |
![]() | GetHashCode | このインスタンスのハッシュ コードを返します。 ( Attribute から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | IsDefaultAttribute | 派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 ( Attribute から継承されます。) |
![]() | IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 ( Attribute から継承されます。) |
![]() | Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 ( Attribute から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

XmlTypeAttribute メンバ
この属性が適用された対象が XmlSerializer によってシリアル化されるときに生成される XML スキーマを制御します。
XmlTypeAttribute データ型で公開されるメンバを以下の表に示します。


名前 | 説明 | |
---|---|---|
![]() ![]() ![]() ![]() | TypeId | 派生クラスに実装されている場合は、この Attribute の一意の識別子を取得します。(Attribute から継承されます。) |
![]() | TypeName | XML 型の名前を取得または設定します。 |

名前 | 説明 | |
---|---|---|
![]() | Equals | オーバーロードされます。 ( Attribute から継承されます。) |
![]() | GetCustomAttribute | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用された指定した型のカスタム属性を取得します。 (Attribute から継承されます。) |
![]() | GetCustomAttributes | オーバーロードされます。 アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されたカスタム属性の配列を取得します。 (Attribute から継承されます。) |
![]() | GetHashCode | このインスタンスのハッシュ コードを返します。 (Attribute から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | IsDefaultAttribute | 派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラスの既定値かどうかを示します。 (Attribute から継承されます。) |
![]() | IsDefined | オーバーロードされます。 指定した型のカスタム属性が、アセンブリ、モジュール、型のメンバ、またはメソッド パラメータに適用されているかどうかを判断します。 (Attribute から継承されます。) |
![]() | Match | 派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンスが等しいかどうかを示す値を返します。 (Attribute から継承されます。) |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

Weblioに収録されているすべての辞書からXmlTypeAttributeを検索する場合は、下記のリンクをクリックしてください。

- XmlTypeAttributeのページへのリンク