XmlTypeAttribute コンストラクタとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > XmlTypeAttribute コンストラクタの意味・解説 

XmlTypeAttribute コンストラクタ (String)

XmlTypeAttribute クラス新しインスタンス初期化しXML 型の名前を指定します

名前空間: System.Xml.Serialization
アセンブリ: 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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlTypeAttribute クラス
XmlTypeAttribute メンバ
System.Xml.Serialization 名前空間

XmlTypeAttribute コンストラクタ

XmlTypeAttribute クラス新しインスタンス初期化します。
オーバーロードの一覧オーバーロードの一覧

名前 説明
XmlTypeAttribute () XmlTypeAttribute クラス新しインスタンス初期化します。

.NET Compact Framework によってサポートされています。

XmlTypeAttribute (String) XmlTypeAttribute クラス新しインスタンス初期化しXML 型の名前を指定します

.NET Compact Framework によってサポートされています。

参照参照

関連項目

XmlTypeAttribute クラス
XmlTypeAttribute メンバ
System.Xml.Serialization 名前空間

XmlTypeAttribute コンストラクタ ()

XmlTypeAttribute クラス新しインスタンス初期化します。

名前空間: System.Xml.Serialization
アセンブリ: System.Xml (system.xml.dll 内)
構文構文

Dim instance As New XmlTypeAttribute
public XmlTypeAttribute ()
public:
XmlTypeAttribute ()
public XmlTypeAttribute ()
public function XmlTypeAttribute ()
使用例使用例

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
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlTypeAttribute クラス
XmlTypeAttribute メンバ
System.Xml.Serialization 名前空間



英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「XmlTypeAttribute コンストラクタ」の関連用語

XmlTypeAttribute コンストラクタのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



XmlTypeAttribute コンストラクタのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2024 Microsoft.All rights reserved.

©2024 GRAS Group, Inc.RSS