次の方法で共有


XmlSerializer コンストラクタ (Type, XmlAttributeOverrides, Type , XmlRootAttribute, String)

Object 型のオブジェクトを XML ドキュメント インスタンスにシリアル化したり、XML ドキュメント インスタンスを Object 型のオブジェクトに逆シリアル化したりできる、XmlSerializer クラスの新しいインスタンスを初期化します。シリアル化される各オブジェクトはそれ自体がクラスのインスタンスを含むことができ、それをこのオーバーロードによって他のクラスでオーバーライドします。このオーバーロードでは、すべての XML 要素の既定の名前空間、および XML ルート要素として使用するクラスも指定します。

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

構文

'宣言
Public Sub New ( _
    type As Type, _
    overrides As XmlAttributeOverrides, _
    extraTypes As Type(), _
    root As XmlRootAttribute, _
    defaultNamespace As String _
)
'使用
Dim type As Type
Dim overrides As XmlAttributeOverrides
Dim extraTypes As Type()
Dim root As XmlRootAttribute
Dim defaultNamespace As String

Dim instance As New XmlSerializer(type, overrides, extraTypes, root, defaultNamespace)
public XmlSerializer (
    Type type,
    XmlAttributeOverrides overrides,
    Type[] extraTypes,
    XmlRootAttribute root,
    string defaultNamespace
)
public:
XmlSerializer (
    Type^ type, 
    XmlAttributeOverrides^ overrides, 
    array<Type^>^ extraTypes, 
    XmlRootAttribute^ root, 
    String^ defaultNamespace
)
public XmlSerializer (
    Type type, 
    XmlAttributeOverrides overrides, 
    Type[] extraTypes, 
    XmlRootAttribute root, 
    String defaultNamespace
)
public function XmlSerializer (
    type : Type, 
    overrides : XmlAttributeOverrides, 
    extraTypes : Type[], 
    root : XmlRootAttribute, 
    defaultNamespace : String
)

パラメータ

  • type
    XmlSerializer がシリアル化できるオブジェクトの型。
  • overrides
    type パラメータで指定されたクラスの動作を拡張またはオーバーライドする XmlAttributeOverrides
  • extraTypes
    シリアル化する追加のオブジェクト型の Type 配列。
  • defaultNamespace
    XML ドキュメント内のすべての XML 要素の既定の名前空間。

解説

overrides パラメータにより、基本クラスの動作を拡張またはオーバーライドするクラスをシリアル化する XmlSerializer を作成できます。たとえば DLL を指定すると、この DLL に含まれるクラスを継承または拡張するクラスを作成できます。このようなクラスをシリアル化するには、XmlSerializer の構築時に XmlAttributeOverrides クラスのインスタンスを使用する必要があります。詳細については、XmlAttributeOverrides のトピックを参照してください。

既定では、パブリック プロパティまたはパブリック フィールドがオブジェクトまたはオブジェクトの配列を返したときには、それらのオブジェクトの型が自動的にシリアル化されます。ただし、Object 型の配列を返すフィールドまたはプロパティがクラスに含まれている場合は、すべてのオブジェクトが配列に挿入されます。この場合、XmlSerializer に対して、Object 配列に挿入される可能性のあるすべてのオブジェクトの型を通知しておく必要があります。この場合は、extraTypes パラメータを使用して、シリアル化または逆シリアル化する追加のオブジェクト型を指定する必要があります。

XML ドキュメントのルート要素には、他のすべての要素が入っています。既定では、type パラメータで指定されたオブジェクトがルート要素としてシリアル化されます。ルート要素の XML 要素名などのプロパティは、type オブジェクトから取得されます。ただし、root パラメータを使用すると、異なる名前空間や要素名などを設定するために使用できる XmlRootAttribute オブジェクトを指定して、既定のオブジェクトの情報を置き換えることができます。

defaultName パラメータを使用して、XmlSerializer が生成するすべての XML 要素の既定の名前空間を指定します。

使用例

DLL に定義されているクラスのインスタンスをシリアル化するため、そのクラス内のパブリック メンバをオーバーライドする例を次に示します。この例では、追加する型の配列、すべての XML 要素の既定の名前空間、および XML ルート要素の情報を提供するために使用するクラスも指定しています。この例では、先頭部分のコードが HighSchool という名前の DLL にコンパイル済みであることを前提としています。

'Beginning of the HighSchool.dll 
Imports System
Imports System.IO
Imports System.Xml
Imports System.Xml.Serialization
Imports Microsoft.VisualBasic
' Imports HighSchool

Namespace HighSchool

    Public Class Student
        Public Name As String
        Public ID As Integer
    End Class 'Student


    Public Class ClassRoom
        Public Students() As Student
    End Class 'ClassRoom
End Namespace 'HighSchool

Namespace College
    Public Class Graduate
        Inherits HighSchool.Student

        Public Sub New()
        End Sub 'New
        ' Add a new field named University.
        Public University As String
        ' Use extra types to use this field.
        Public Info() As Object
    End Class 'Graduate


    Public Class Address
        Public City As String
    End Class 'Address


    Public Class Phone
        Public Number As String
    End Class 'Phone


    Public Class Run

        Public Shared Sub Main()
            Dim test As New Run()
            test.WriteOverriddenAttributes("College.xml")
            test.ReadOverriddenAttributes("College.xml")
        End Sub 'Main


        Private Sub WriteOverriddenAttributes(ByVal filename As String)
            ' Writing the file requires a TextWriter.
            Dim myStreamWriter As New StreamWriter(filename)
            ' Create an XMLAttributeOverrides class.
            Dim attrOverrides As New XmlAttributeOverrides()
            ' Create the XmlAttributes class.
            Dim attrs As New XmlAttributes()
            ' Override the Student class. "Alumni" is the name
            ' of the overriding element in the XML output. 

            Dim attr As New XmlElementAttribute("Alumni", GetType(Graduate))
            ' Add the XmlElementAttribute to the collection of
            ' elements in the XmlAttributes object. 
            attrs.XmlElements.Add(attr)
            ' Add the XmlAttributes to the XmlAttributeOverrides.
            ' "Students" is the name being overridden. 
            attrOverrides.Add(GetType(HighSchool.ClassRoom), "Students", attrs)

            ' Create array of extra types.
            Dim extraTypes(1) As Type
            extraTypes(0) = GetType(Address)
            extraTypes(1) = GetType(Phone)

            ' Create an XmlRootAttribute.
            Dim root As New XmlRootAttribute("Graduates")

            ' Create the XmlSerializer with the
            ' XmlAttributeOverrides object. 
            Dim mySerializer As New XmlSerializer(GetType(HighSchool.ClassRoom), _
                attrOverrides, extraTypes, root, "https://www.microsoft.com")

            Dim oMyClass As New HighSchool.ClassRoom()

            Dim g1 As New Graduate()
            g1.Name = "Jacki"
            g1.ID = 1
            g1.University = "Alma"

            Dim g2 As New Graduate()
            g2.Name = "Megan"
            g2.ID = 2
            g2.University = "CM"

            Dim myArray As HighSchool.Student() = {g1, g2}

            oMyClass.Students = myArray

            ' Create extra information.
            Dim a1 As New Address()
            a1.City = "Ionia"
            Dim a2 As New Address()
            a2.City = "Stamford"
            Dim p1 As New Phone()
            p1.Number = "555-0101"
            Dim p2 As New Phone()
            p2.Number = "555-0100"

            Dim o1() As Object = {a1, p1}
            Dim o2() As Object = {a2, p2}

            g1.Info = o1
            g2.Info = o2
            mySerializer.Serialize(myStreamWriter, oMyClass)
            myStreamWriter.Close()
        End Sub 'WriteOverriddenAttributes


        Private Sub ReadOverriddenAttributes(ByVal filename As String)
            ' The majority of the code here is the same as that in the
            ' WriteOverriddenAttributes method. Because the XML being read
            ' doesn't conform to the schema defined by the DLL, the
            ' XMLAttributesOverrides must be used to create an
            ' XmlSerializer instance to read the XML document.

            Dim attrOverrides As New XmlAttributeOverrides()
            Dim attrs As New XmlAttributes()
            Dim attr As New XmlElementAttribute("Alumni", GetType(Graduate))
            attrs.XmlElements.Add(attr)
            attrOverrides.Add(GetType(HighSchool.ClassRoom), "Students", attrs)

            Dim extraTypes(1) As Type
            extraTypes(0) = GetType(Address)
            extraTypes(1) = GetType(Phone)

            Dim root As New XmlRootAttribute("Graduates")

            Dim readSerializer As New XmlSerializer(GetType(HighSchool.ClassRoom), _
                attrOverrides, extraTypes, root, "https://www.microsoft.com")

            ' A FileStream object is required to read the file. 
            Dim fs As New FileStream(filename, FileMode.Open)

            Dim oMyClass As HighSchool.ClassRoom
            oMyClass = CType(readSerializer.Deserialize(fs), HighSchool.ClassRoom)

            ' Here is the difference between reading and writing an
            ' XML document: You must declare an object of the derived
            ' type (Graduate) and cast the Student instance to it.
            Dim g As Graduate
            Dim a As Address
            Dim p As Phone
            Dim grad As Graduate
            For Each grad In oMyClass.Students
                g = CType(grad, Graduate)
                Console.Write((g.Name & ControlChars.Tab))
                Console.Write((g.ID & ControlChars.Tab))
                Console.Write((g.University & ControlChars.Cr))
                a = CType(g.Info(0), Address)
                Console.WriteLine(a.City)
                p = CType(g.Info(1), Phone)
                Console.WriteLine(p.Number)
            Next grad
        End Sub 'ReadOverriddenAttributes
    End Class 'Run
End Namespace 'College
// Beginning of the HighSchool.dll 

namespace HighSchool
{
   public class Student
   {
      public string Name;
      public int ID;
   }
    
   public class MyClass
   {
      public Student[] Students;
   }
}

namespace College
   {
   using System;
   using System.IO;
   using System.Xml;
   using System.Xml.Serialization; 
   using HighSchool;

    public class Graduate:HighSchool.Student
    {
       public Graduate(){}
       // Add a new field named University.
       public string University;
       // Use extra types to use this field.
       public object[]Info;
    }
 
    public class Address
    {
       public string City;
    }
 
    public class Phone
    {
       public string Number;
    }
    
   public class Run
   {
      public static void Main()
      {
         Run test = new Run();
         test.WriteOverriddenAttributes("College.xml");
         test.ReadOverriddenAttributes("College.xml");
      }
 
      private void WriteOverriddenAttributes(string filename)
      {
         // Writing the file requires a TextWriter.
         TextWriter myStreamWriter = new StreamWriter(filename);
         // Create an XMLAttributeOverrides class.
         XmlAttributeOverrides attrOverrides = 
         new XmlAttributeOverrides();
         // Create the XmlAttributes class.
         XmlAttributes attrs = new XmlAttributes();
         /* Override the Student class. "Alumni" is the name
         of the overriding element in the XML output. */

         XmlElementAttribute attr = 
         new XmlElementAttribute("Alumni", typeof(Graduate));
         /* Add the XmlElementAttribute to the collection of
         elements in the XmlAttributes object. */
         attrs.XmlElements.Add(attr);
         /* Add the XmlAttributes to the XmlAttributeOverrides. 
         "Students" is the name being overridden. */
         attrOverrides.Add(typeof(HighSchool.MyClass), 
         "Students", attrs);
 
         // Create array of extra types.
         Type [] extraTypes = new Type[2];
         extraTypes[0]=typeof(Address);
         extraTypes[1]=typeof(Phone);
 
         // Create an XmlRootAttribute.
         XmlRootAttribute root = new XmlRootAttribute("Graduates");
          
         /* Create the XmlSerializer with the 
         XmlAttributeOverrides object. */
         XmlSerializer mySerializer = new XmlSerializer
         (typeof(HighSchool.MyClass), attrOverrides, extraTypes,
         root, "https://www.microsoft.com");
 
         MyClass myClass= new MyClass();

         Graduate g1 = new Graduate();
         g1.Name = "Jacki";
         g1.ID = 1;
         g1.University = "Alma";

         Graduate g2 = new Graduate();
         g2.Name = "Megan";
         g2.ID = 2;
         g2.University = "CM";

         Student[] myArray = {g1,g2};

         myClass.Students = myArray;
 
         // Create extra information.
         Address a1 = new Address();
         a1.City = "Ionia";
         Address a2 = new Address();
         a2.City = "Stamford";
         Phone p1 = new Phone();
         p1.Number = "555-0101";
         Phone p2 = new Phone();
         p2.Number = "555-0100";
 
         Object[]o1 = new Object[2]{a1, p1};
         Object[]o2 = new Object[2]{a2,p2};
 
         g1.Info = o1;
         g2.Info = o2;
         mySerializer.Serialize(myStreamWriter,myClass);
         myStreamWriter.Close();
      }

      private void ReadOverriddenAttributes(string filename)
      {
         /* The majority of the code here is the same as that in the
         WriteOverriddenAttributes method. Because the XML being read
         doesn't conform to the schema defined by the DLL, the
         XMLAttributesOverrides must be used to create an 
         XmlSerializer instance to read the XML document.*/
          
         XmlAttributeOverrides attrOverrides = new 
         XmlAttributeOverrides();
         XmlAttributes attrs = new XmlAttributes();
         XmlElementAttribute attr = 
         new XmlElementAttribute("Alumni", typeof(Graduate));
         attrs.XmlElements.Add(attr);
         attrOverrides.Add(typeof(HighSchool.MyClass), 
         "Students", attrs);

         Type [] extraTypes = new Type[2];
         extraTypes[0] = typeof(Address);
         extraTypes[1] = typeof(Phone);
 
         XmlRootAttribute root = new XmlRootAttribute("Graduates");
          
         XmlSerializer readSerializer = new XmlSerializer
         (typeof(HighSchool.MyClass), attrOverrides, extraTypes,
         root, "https://www.microsoft.com");

         // A FileStream object is required to read the file. 
         FileStream fs = new FileStream(filename, FileMode.Open);
          
         MyClass myClass;
         myClass = (MyClass) readSerializer.Deserialize(fs);

         /* Here is the difference between reading and writing an 
         XML document: You must declare an object of the derived 
         type (Graduate) and cast the Student instance to it.*/
         Graduate g;
         Address a;
         Phone p;
         foreach(Graduate grad in myClass.Students)
         {
            g = (Graduate) grad;
            Console.Write(g.Name + "\t");
            Console.Write(g.ID + "\t");
            Console.Write(g.University + "\n");
            a = (Address) g.Info[0];
            Console.WriteLine(a.City);
            p = (Phone) g.Info[1];
            Console.WriteLine(p.Number);
         }
      }
   }
}
// Beginning of the HighSchool.dll 
#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;

namespace HighSchool
{
   public ref class Student
   {
   public:
      String^ Name;
      int ID;
   };

   public ref class MyClass
   {
   public:
      array<Student^>^Students;
   };
}

namespace College
{

using namespace HighSchool;
   public ref class Graduate: public HighSchool::Student
   {
   public:
      Graduate(){}

      // Add a new field named University.
      String^ University;

      // Use extra types to use this field.
      array<Object^>^Info;
   };

   public ref class Address
   {
   public:
      String^ City;
   };

   public ref class Phone
   {
   public:
      String^ Number;
   };

   public ref class Run
   {
   public:
      static void main()
      {
         Run^ test = gcnew Run;
         test->WriteOverriddenAttributes( "College.xml" );
         test->ReadOverriddenAttributes( "College.xml" );
      }

   private:
      void WriteOverriddenAttributes( String^ filename )
      {
         // Writing the file requires a TextWriter.
         TextWriter^ myStreamWriter = gcnew StreamWriter( filename );

         // Create an XMLAttributeOverrides class.
         XmlAttributeOverrides^ attrOverrides = gcnew XmlAttributeOverrides;

         // Create the XmlAttributes class.
         XmlAttributes^ attrs = gcnew XmlAttributes;

         /* Override the Student class. "Alumni" is the name
               of the overriding element in the XML output. */
         XmlElementAttribute^ attr = gcnew XmlElementAttribute( "Alumni",Graduate::typeid );

         /* Add the XmlElementAttribute to the collection of
               elements in the XmlAttributes object. */
         attrs->XmlElements->Add( attr );

         /* Add the XmlAttributes to the XmlAttributeOverrides. 
               "Students" is the name being overridden. */
         attrOverrides->Add( HighSchool::MyClass::typeid, "Students", attrs );

         // Create array of extra types.
         array<Type^>^extraTypes = gcnew array<Type^>(2);
         extraTypes[ 0 ] = Address::typeid;
         extraTypes[ 1 ] = Phone::typeid;

         // Create an XmlRootAttribute.
         XmlRootAttribute^ root = gcnew XmlRootAttribute( "Graduates" );

         /* Create the XmlSerializer with the 
               XmlAttributeOverrides object. */
         XmlSerializer^ mySerializer = gcnew XmlSerializer( HighSchool::MyClass::typeid,attrOverrides,extraTypes,root,"https://www.microsoft.com" );
         MyClass ^ myClass = gcnew MyClass;
         Graduate^ g1 = gcnew Graduate;
         g1->Name = "Jacki";
         g1->ID = 1;
         g1->University = "Alma";
         Graduate^ g2 = gcnew Graduate;
         g2->Name = "Megan";
         g2->ID = 2;
         g2->University = "CM";
         array<Student^>^myArray = {g1,g2};
         myClass->Students = myArray;

         // Create extra information.
         Address^ a1 = gcnew Address;
         a1->City = "Ionia";
         Address^ a2 = gcnew Address;
         a2->City = "Stamford";
         Phone^ p1 = gcnew Phone;
         p1->Number = "555-0101";
         Phone^ p2 = gcnew Phone;
         p2->Number = "555-0100";
         array<Object^>^o1 = {a1,p1};
         array<Object^>^o2 = {a2,p2};
         g1->Info = o1;
         g2->Info = o2;
         mySerializer->Serialize( myStreamWriter, myClass );
         myStreamWriter->Close();
      }

      void ReadOverriddenAttributes( String^ filename )
      {
         /* The majority of the code here is the same as that in the
               WriteOverriddenAttributes method. Because the XML being read
               doesn't conform to the schema defined by the DLL, the
               XMLAttributesOverrides must be used to create an 
               XmlSerializer instance to read the XML document.*/
         XmlAttributeOverrides^ attrOverrides = gcnew XmlAttributeOverrides;
         XmlAttributes^ attrs = gcnew XmlAttributes;
         XmlElementAttribute^ attr = gcnew XmlElementAttribute( "Alumni",Graduate::typeid );
         attrs->XmlElements->Add( attr );
         attrOverrides->Add( HighSchool::MyClass::typeid, "Students", attrs );
         array<Type^>^extraTypes = gcnew array<Type^>(2);
         extraTypes[ 0 ] = Address::typeid;
         extraTypes[ 1 ] = Phone::typeid;
         XmlRootAttribute^ root = gcnew XmlRootAttribute( "Graduates" );
         XmlSerializer^ readSerializer = gcnew XmlSerializer( HighSchool::MyClass::typeid,attrOverrides,extraTypes,root,"https://www.microsoft.com" );

         // A FileStream object is required to read the file. 
         FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
         MyClass ^ myClass;
         myClass = dynamic_cast<MyClass^>(readSerializer->Deserialize( fs ));
         
         /* Here is the difference between reading and writing an 
               XML document: You must declare an object of the derived 
               type (Graduate) and cast the Student instance to it.*/
         Graduate^ g;
         Address^ a;
         Phone^ p;
         System::Collections::IEnumerator^ myEnum = myClass->Students->GetEnumerator();
         while ( myEnum->MoveNext() )
         {
            Graduate^ grad = safe_cast<Graduate^>(myEnum->Current);
            g = dynamic_cast<Graduate^>(grad);
            Console::Write( "{0}\t", g->Name );
            Console::Write( "{0}\t", g->ID );
            Console::Write( "{0}\n", g->University );
            a = dynamic_cast<Address^>(g->Info[ 0 ]);
            Console::WriteLine( a->City );
            p = dynamic_cast<Phone^>(g->Info[ 1 ]);
            Console::WriteLine( p->Number );
         }
      }
   };
}

int main()
{
   College::Run::main();
}
package College;

import System.*;
import System.IO.*;
import System.Xml.*;
import System.Xml.Serialization.*;
import HighSchool.*;
public class Graduate extends HighSchool.Student
{
    public Graduate()
    {
    } //Graduate
    // Add a new field named University.
    public String university;
    // Use extra types to use this field.
    public Object info[];
} //Graduate

public class Address
{
    public String city;
} //Address

public class Phone
{
    public String number;
} //Phone

public class Run
{
    public static void main(String[] args)
    {
        Run test = new Run();
        test.WriteOverriddenAttributes("College.xml");
        test.ReadOverriddenAttributes("College.xml");
    } //main

    private void WriteOverriddenAttributes(String filename)
    {
        // Writing the file requires a TextWriter.
        TextWriter myStreamWriter = new StreamWriter(filename);

        // Create an XMLAttributeOverrides class.
        XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();

        // Create the XmlAttributes class.
        XmlAttributes attrs = new XmlAttributes();

        /* Override the Student class. "Alumni" is the name
           of the overriding element in the XML output. */
        XmlElementAttribute attr =
            new XmlElementAttribute("Alumni", Graduate.class.ToType());

        /* Add the XmlElementAttribute to the collection of
           elements in the XmlAttributes object. */
        attrs.get_XmlElements().Add(attr);

        /* Add the XmlAttributes to the XmlAttributeOverrides. 
          "Students" is the name being overridden. */
        attrOverrides.Add(HighSchool.MyClass.class.ToType(), "students", attrs);

        // Create array of extra types.
        Type extraTypes[] = new Type[2];
        extraTypes.set_Item(0, Address.class.ToType());
        extraTypes.set_Item(1, Phone.class.ToType());

        // Create an XmlRootAttribute.
        XmlRootAttribute root = new XmlRootAttribute("Graduates");

        /* Create the XmlSerializer with the 
           XmlAttributeOverrides object. */
        XmlSerializer mySerializer =
            new XmlSerializer(HighSchool.MyClass.class.ToType(), attrOverrides,
            extraTypes, root, "https://www.microsoft.com");
        MyClass myClass = new MyClass();
        
        Graduate g1 = new Graduate();
        g1.name = "Jacki";
        g1.iD = 1;
        g1.university = "Alma";

        Graduate g2 = new Graduate();
        g2.name = "Megan";
        g2.iD = 2;
        g2.university = "CM";

        Student myArray[] =  { g1, g2 };
        myClass.students = myArray;

        // Create extra information.
        Address a1 = new Address();
        a1.city = "Ionia";

        Address a2 = new Address();
        a2.city = "Stamford";

        Phone p1 = new Phone();
        p1.number = "000-0000";

        Phone p2 = new Phone();
        p2.number = "555-0100";

        Object o1[] = new Object[] { a1, p1 };
        Object o2[] = new Object[] { a2, p2 };

        g1.info = o1;
        g2.info = o2;
        mySerializer.Serialize(myStreamWriter, myClass);
        myStreamWriter.Close();
    } //WriteOverriddenAttributes

    private void ReadOverriddenAttributes(String filename)
    {
        /* The majority of the code here is the same as that in the
           WriteOverriddenAttributes method. Because the XML being read
           doesn't conform to the schema defined by the DLL, the
           XMLAttributesOverrides must be used to create an 
           XmlSerializer instance to read the XML document.*/
        XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();
        XmlAttributes attrs = new XmlAttributes();
        XmlElementAttribute attr =
            new XmlElementAttribute("Alumni", Graduate.class.ToType());

        attrs.get_XmlElements().Add(attr);
        attrOverrides.Add(HighSchool.MyClass.class.ToType(), "students", attrs);

        Type extraTypes[] = new Type[2];
        extraTypes.set_Item(0, Address.class.ToType());
        extraTypes.set_Item(1, Phone.class.ToType());

        XmlRootAttribute root = new XmlRootAttribute("Graduates");
        XmlSerializer readSerializer =
            new XmlSerializer(HighSchool.MyClass.class.ToType(), attrOverrides,
            extraTypes, root, "https://www.microsoft.com");

        // A FileStream object is required to read the file. 
        FileStream fs = new FileStream(filename, FileMode.Open);
        MyClass myClass;
        myClass = (MyClass)readSerializer.Deserialize(fs);

        /* Here is the difference between reading and writing an 
           XML document: You must declare an object of the derived 
           type (Graduate) and cast the Student instance to it.*/
        Graduate g;
        Address a;
        Phone p;

        for (int iCtr = 0; iCtr < myClass.students.length; iCtr++) {
            Graduate grad = (Graduate)myClass.students[iCtr];
            g = (Graduate)grad;
            Console.Write(g.name + "\t");
            Console.Write(g.iD + "\t");
            Console.Write(g.university + "\n");
            a = (Address)g.info[0];
            Console.WriteLine(a.city);
            p = (Phone)g.info[1];
            Console.WriteLine(p.number);
        }
    } //ReadOverriddenAttributes
} //Run
package HighSchool;
// Beginning of the HighSchool.dll 
public class Student
{
    public String name;
    public int iD;
} //Student

public class MyClass
{
    public Student students[];
} //MyClass

プラットフォーム

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

参照

関連項目

XmlSerializer クラス
XmlSerializer メンバ
System.Xml.Serialization 名前空間
XmlAttributeOverrides クラス
XmlRootAttribute クラス
XmlAttributes クラス

その他の技術情報

XML シリアル化の概要
方法 : XML ストリームの代替要素名を指定する
属性を使用した XML シリアル化の制御
XML シリアル化の例
XML スキーマ定義ツール (Xsd.exe)