XmlElementAttributeとは? わかりやすく解説

XmlElementAttribute クラス

パブリック フィールドパブリック プロパティ保持するオブジェクトを XmlSerializer がシリアル化または逆シリアル化するときに、それらのフィールドプロパティXML 要素を表すかどうか示します

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

<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field
 Or AttributeTargets.Parameter Or AttributeTargets.ReturnValue,
 AllowMultiple:=True)> _
Public Class XmlElementAttribute
    Inherits Attribute
Dim instance As XmlElementAttribute
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue,
 AllowMultiple=true)] 
public class XmlElementAttribute : Attribute
[AttributeUsageAttribute(AttributeTargets::Property|AttributeTargets::Field|AttributeTargets::Parameter|AttributeTargets::ReturnValue,
 AllowMultiple=true)] 
public ref class XmlElementAttribute : public
 Attribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue,
 AllowMultiple=true) */ 
public class XmlElementAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue,
 AllowMultiple=true) 
public class XmlElementAttribute extends
 Attribute
解説解説

XmlElementAttribute は、XmlSerializerオブジェクトシリアル化または逆シリアル化する方法制御する一連の属性1 つです。類似する属性の完全な一覧については、「XML シリアル化制御する属性」を参照してください

通常XML ドキュメントには XML 要素含まれており、各 XML 要素は、開始タグ終了タグタグ間のデータという 3 つの部分構成されています。XML タグ入れ子できます。つまり、タグ間のデータXML 要素になっている場合あります。これにより、ある要素別の要素を囲むことができるため、ドキュメントデータ階層的に格納できますXML 要素には、属性を含むこともできます

要素名や名前空間など、XML 要素特性制御するには、XmlElementAttributeパブリック フィールドまたは読み取り/書き込み可能なパブリック プロパティ適用します。

XmlElementAttribute は、オブジェクト配列返すフィールドには何回でも適用できます。その理由は、その配列挿入できる各種の型を、Type プロパティ使用して指定できるようにするためです。たとえば、次の C# コード配列には、文字列整数両方格納できます

 public class Things{
    [XmlElement(DataType = typeof(string)),
    XmlElement(DataType = typeof(int))]
    public object[] StringsAndInts;
 }

結果として次のような XML生成されます。

 <Things>
    <string>Hello</string>
    <int>999</int>
    <string>World</string>
 </Things>

ElementName プロパティの値を指定せずに XmlElementAttribute何回適用した場合各要素には、配列挿入できるオブジェクトの型の名前が付けられます。

配列返すフィールドまたはプロパティXmlElementAttribute適用すると、その配列内の項目は XML 要素シーケンスとしてエンコードされます

これに対しこのようなフィールドまたはプロパティXmlElementAttribute適用しないと、それらが返す配列内の項目は単なる要素シーケンスとしてエンコードされ、それぞれフィールドまたはプロパティの名前が付いた要素として入れ子なります配列シリアル化方法制御する場合は、XmlArrayAttribute 属性と XmlArrayItemAttribute 属性使用します

Type プロパティ設定して、元のフィールドまたはプロパティ (XmlElementAttribute適用したフィールドまたはプロパティ) の型から派生する型を指定できます

フィールドまたはプロパティが ArrayList を返す場合は、そのメンバXmlElementAttribute複数インスタンス適用できます。各インスタンスType プロパティに、配列挿入できるオブジェクトの型を設定します

属性使用方法については、「属性使用したメタデータ拡張」を参照してください

メモメモ

コードでは、XmlElementAttribute代わりに XmlElement という短い語を使用できます

使用例使用例

Group という名前のクラスシリアル化し、そのメンバいくつかXmlElementAttribute適用する例を次に示しますEmployees という名前のフィールドは、Employee オブジェクト配列返します。この例では、XmlElementAttribute は、結果として生成される XML入れ子にしないよう指定してます。これは、配列内の項目の既定動作です。

Imports System
Imports System.Collections
Imports System.IO
Imports System.Xml.Serialization


Public Class Group
    ' Set the element name and namespace of the XML element.
    <XmlElement(ElementName := "Members", _
     Namespace := "http://www.cpandl.com")>
 _    
    Public Employees() As Employee
    
    <XmlElement(DataType := "double", _
     ElementName := "Building")> _
    Public GroupID As Double
    
    <XmlElement(DataType := "hexBinary")> _
    Public HexBytes() As Byte
    
    <XmlElement(DataType := "boolean")> _
    Public IsActive As Boolean
    
    <XmlElement(GetType(Manager))> _
    Public Manager As Employee
    
    <XmlElement(GetType(Integer), _
        ElementName := "ObjectNumber"), _
     XmlElement(GetType(String), _
        ElementName := "ObjectString")> _
    Public ExtraInfo As ArrayList
End Class

Public Class Employee
    Public Name As String
End Class

Public Class Manager
    Inherits Employee
    Public Level As Integer
End Class

Public Class Run
    
    Public Shared Sub Main()
        Dim test As New
 Run()
        test.SerializeObject("FirstDoc.xml")
        test.DeserializeObject("FirstDoc.xml")
    End Sub
    
    Public Sub SerializeObject(filename As
 String)
        ' Create the XmlSerializer.
        Dim s As New XmlSerializer(GetType(Group))
        
        ' To write the file, a TextWriter is required.
        Dim writer As New
 StreamWriter(filename)
        
        ' Create an instance of the group to serialize, and set
        ' its properties. 
        Dim group As New
 Group()
        group.GroupID = 10.089f
        group.IsActive = False
        
        group.HexBytes = New Byte() {Convert.ToByte(100)}
        
        Dim x As New Employee()
        Dim y As New Employee()
        
        x.Name = "Jack"
        y.Name = "Jill"
        
        group.Employees = New Employee() {x, y}
        
        Dim mgr As New Manager()
        mgr.Name = "Sara"
        mgr.Level = 4
        group.Manager = mgr
        
        ' Add a number and a string to the
        ' ArrayList returned by the ExtraInfo property. 
        group.ExtraInfo = New ArrayList()
        group.ExtraInfo.Add(42)
        group.ExtraInfo.Add("Answer")
        
        ' Serialize the object, and close the TextWriter.      
        s.Serialize(writer, group)
        writer.Close()
    End Sub    
    
    Public Sub DeserializeObject(filename As
 String)
        Dim fs As New FileStream(filename,
 FileMode.Open)
        Dim x As New XmlSerializer(GetType(Group))
        Dim g As Group = CType(x.Deserialize(fs),
 Group)
        Console.WriteLine(g.Manager.Name)
        Console.WriteLine(g.GroupID)
        Console.WriteLine(g.HexBytes(0))

        Dim e As Employee
        For Each e In g.Employees
            Console.WriteLine(e.Name)
        Next e
    End Sub
End Class

using System;
using System.Collections;
using System.IO;
using System.Xml.Serialization;

public class Group
{
   /* Set the element name and namespace of the XML element.
   By applying an XmlElementAttribute to an array,  you instruct
   the XmlSerializer to serialize the array as a series of XML
   elements, instead of a nested set of elements. */
   
   [XmlElement(
   ElementName = "Members",
   Namespace = "http://www.cpandl.com")]
   public Employee[] Employees;
      
   [XmlElement(DataType = "double",
   ElementName = "Building")]
   public double GroupID;

   [XmlElement(DataType = "hexBinary")]
   public byte [] HexBytes;


   [XmlElement(DataType = "boolean")]
   public bool IsActive;

   [XmlElement(Type = typeof(Manager))]
   public Employee Manager;

   [XmlElement(typeof(int),
   ElementName = "ObjectNumber"),
   XmlElement(typeof(string),
   ElementName = "ObjectString")]
   public ArrayList ExtraInfo;
}   

public class Employee
{
   public string Name;
}

public class Manager:Employee{
   public int Level;
}

public class Run
{
    public static void Main()
    {
       Run test = new Run();
       test.SerializeObject("FirstDoc.xml");
       test.DeserializeObject("FirstDoc.xml");
    }


   public void SerializeObject(string
 filename)
   {
      // Create the XmlSerializer.
      XmlSerializer s = new XmlSerializer(typeof(Group));

      // To write the file, a TextWriter is required.
      TextWriter writer = new StreamWriter(filename);

      /* Create an instance of the group to serialize, and set
         its properties. */
      Group group = new Group();
      group.GroupID = 10.089f;
      group.IsActive = false;
      
      group.HexBytes = new byte[1]{Convert.ToByte(100)};

      Employee x = new Employee();
      Employee y = new Employee();

      x.Name = "Jack";
      y.Name = "Jill";
      
      group.Employees = new Employee[2]{x,y};

      Manager mgr = new Manager();
      mgr.Name = "Sara";
      mgr.Level = 4;
      group.Manager = mgr;

      /* Add a number and a string to the 
      ArrayList returned by the ExtraInfo property. */
      group.ExtraInfo = new ArrayList();
      group.ExtraInfo.Add(42);
      group.ExtraInfo.Add("Answer");

      // Serialize the object, and close the TextWriter.      
      s.Serialize(writer, group);
      writer.Close();
   }

   public void DeserializeObject(string
 filename)
   {
      FileStream fs = new FileStream(filename, FileMode.Open);
      XmlSerializer x = new XmlSerializer(typeof(Group));
      Group g = (Group) x.Deserialize(fs);
      Console.WriteLine(g.Manager.Name);
      Console.WriteLine(g.GroupID);
      Console.WriteLine(g.HexBytes[0]);
      foreach(Employee e in g.Employees)
      {
         Console.WriteLine(e.Name);
      }
   }
}
   
#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::Collections;
using namespace System::IO;
using namespace System::Xml::Serialization;
public ref class Employee
{
public:
   String^ Name;
};

public ref class Manager: public
 Employee
{
public:
   int Level;
};

public ref class Group
{
public:

   /* Set the element name and namespace of the XML element.
      By applying an XmlElementAttribute to an array,  you instruct
      the XmlSerializer to serialize the array as a series of XML
      elements, instead of a nested set of elements. */

   [XmlElement(
   ElementName="Members",
   Namespace="http://www.cpandl.com")]
   array<Employee^>^Employees;

   [XmlElement(DataType="snippet1>",
   ElementName="Building")]
   double GroupID;

   [XmlElement(DataType="hexBinary")]
   array<Byte>^HexBytes;

   [XmlElement(DataType="boolean")]
   bool IsActive;

   [XmlElement(Type=::Manager::typeid)]
   Employee^ Manager;

   [XmlElement(Int32::typeid,
   ElementName="ObjectNumber"),
   XmlElement(String::typeid,
   ElementName="ObjectString")]
   ArrayList^ ExtraInfo;
};

void SerializeObject( String^ filename )
{
   // Create the XmlSerializer.
   XmlSerializer^ s = gcnew XmlSerializer( Group::typeid );

   // To write the file, a TextWriter is required.
   TextWriter^ writer = gcnew StreamWriter( filename );

   /* Create an instance of the group to serialize, and set
      its properties. */
   Group^ group = gcnew Group;
   group->GroupID = 10.089f;
   group->IsActive = false;
   array<Byte>^temp0 = {Convert::ToByte( 100 )};
   group->HexBytes = temp0;
   Employee^ x = gcnew Employee;
   Employee^ y = gcnew Employee;
   x->Name = "Jack";
   y->Name = "Jill";
   array<Employee^>^temp1 = {x,y};
   group->Employees = temp1;
   Manager^ mgr = gcnew Manager;
   mgr->Name = "Sara";
   mgr->Level = 4;
   group->Manager = mgr;

   /* Add a number and a string to the 
      ArrayList returned by the ExtraInfo property. */
   group->ExtraInfo = gcnew ArrayList;
   group->ExtraInfo->Add( 42 );
   group->ExtraInfo->Add( "Answer" );

   // Serialize the object, and close the TextWriter.      
   s->Serialize( writer, group );
   writer->Close();
}

void DeserializeObject( String^ filename )
{
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   XmlSerializer^ x = gcnew XmlSerializer( Group::typeid );
   Group^ g = dynamic_cast<Group^>(x->Deserialize( fs ));
   Console::WriteLine( g->Manager->Name );
   Console::WriteLine( g->GroupID );
   Console::WriteLine( g->HexBytes[ 0 ] );
   IEnumerator^ myEnum = g->Employees->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Employee^ e = safe_cast<Employee^>(myEnum->Current);
      Console::WriteLine( e->Name );
   }
}

int main()
{
   SerializeObject( "FirstDoc.xml" );
   DeserializeObject( "FirstDoc.xml" );
}
import System.*;
import System.Collections.*;
import System.IO.*;
import System.Xml.Serialization.*;

public class Group
{
    /* Set the element name and namespace of the XML element.
       By applying an XmlElementAttribute to an array,  you instruct
       the XmlSerializer to serialize the array as a series of XML
       elements, instead of a nested set of elements. */
   
    /** @attribute XmlElement(ElementName = "Members",
        Namespace = "http://www.cpandl.com")
     */
    public Employee employees[];   
    /** @attribute XmlElement(DataType = "double", ElementName = "Building")
     */
    public double groupID;   
    /** @attribute XmlElement(DataType = "hexBinary")
     */
    public ubyte hexBytes[];   
    /** @attribute XmlElement(DataType = "boolean")
     */
    public boolean isActive;   
    /** @attribute XmlElement(Type = Manager.class)
     */
    public Employee manager;   
    /** @attribute XmlElement(int.class, ElementName
 = "ObjectNumber")
        @attribute XmlElement(String.class, ElementName = "ObjectString")
     */
    public ArrayList extraInfo;
} //Group

public class Employee
{
    public String name;
} //Employee

public class Manager extends Employee
{
    public int level;
} //Manager

public class Run
{
    public static void main(String[]
 args)
    {
        Run test = new Run();
        test.SerializeObject("FirstDoc.xml");
        test.DeserializeObject("FirstDoc.xml");
    } //main

    public void SerializeObject(String fileName)
    {
        // Create the XmlSerializer.
        XmlSerializer s = new XmlSerializer(Group.class.ToType());

        // To write the file, a TextWriter is required.
        TextWriter writer = new StreamWriter(fileName);

        /* Create an instance of the group to serialize, and set
           its properties. */
        Group group = new Group();
        group.groupID = 10.089f;
        group.isActive = false;
        group.hexBytes = new ubyte[] { Convert.ToByte(100) };

        Employee x = new Employee();
        Employee y = new Employee();

        x.name = "Jack";
        y.name = "Jill";
        group.employees = new Employee[] { x, y };

        Manager mgr = new Manager();
        mgr.name = "Sara";
        mgr.level = 4;
        group.manager = mgr;

        /* Add a number and a string to the 
           ArrayList returned by the ExtraInfo property. */
        group.extraInfo = new ArrayList();
        group.extraInfo.Add((Int32)42);
        group.extraInfo.Add("Answer");

        // Serialize the object, and close the TextWriter.      
        s.Serialize(writer, group);
        writer.Close();
    } //SerializeObject

    public void DeserializeObject(String fileName)
    {
        FileStream fs = new FileStream(fileName, FileMode.Open);
        XmlSerializer x = new XmlSerializer(Group.class.ToType());
        Group g = (Group)x.Deserialize(fs);

        Console.WriteLine(g.manager.name);
        Console.WriteLine(g.groupID);
        Console.WriteLine(g.hexBytes.get_Item(0));
        for (int iCtr = 0; iCtr < g.employees.length;
 iCtr++) {
            Employee e = g.employees[iCtr];
            Console.WriteLine(e.name);
        }
    } //DeserializeObject
} //Run
継承階層継承階層
System.Object
   System.Attribute
    System.Xml.Serialization.XmlElementAttribute
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバ場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlElementAttribute メンバ
System.Xml.Serialization 名前空間
XmlArrayAttribute クラス
XmlAttributeOverrides クラス
XmlAttributes クラス
XmlElementAttributes
XmlAttributes.XmlElements プロパティ
XmlRootAttribute
XmlSerializer
XmlAttributes クラス
その他の技術情報
XML シリアル化概要
方法 : XML ストリーム代替要素名を指定する
属性使用した XML シリアル化制御
XML シリアル化の例
XML スキーマ定義ツール (Xsd.exe)

XmlElementAttribute コンストラクタ ()

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

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

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

XmlElementAttributeクラス適用する例を次に示します

Public Class MyClass1
    <XmlElement()> Public TeacherName As
 String
End Class

public class MyClass
{
   [XmlElement()]
   public string TeacherName;
}

public ref class MyClass
{
public:

   [XmlElement]
   String^ TeacherName;
};

public class MyClass
{
    /** @attribute XmlElement()
     */
    public String teacherName;
} //MyClass
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlElementAttribute クラス
XmlElementAttribute メンバ
System.Xml.Serialization 名前空間

XmlElementAttribute コンストラクタ (String, Type)

XmlElementAttribute の新しインスタンス初期化しXmlElementAttribute適用先であるメンバXML 要素の名前と派生型指定します。このメンバ型が使用されるのは、その型を含むオブジェクトを XmlSerializer がシリアル化する場合です。

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

Public Sub New ( _
    elementName As String, _
    type As Type _
)
Dim elementName As String
Dim type As Type

Dim instance As New XmlElementAttribute(elementName,
 type)
public XmlElementAttribute (
    string elementName,
    Type type
)
public:
XmlElementAttribute (
    String^ elementName, 
    Type^ type
)
public XmlElementAttribute (
    String elementName, 
    Type type
)
public function XmlElementAttribute (
    elementName : String, 
    type : Type
)

パラメータ

elementName

シリアル化されたメンバXML 要素名。

type

メンバの型から派生したオブジェクトType

解説解説

既定では、XmlSerializerクラスインスタンスシリアル化するときは、メンバ名が XML 要素名として使用されます。たとえば、Vehicle という名前のフィールドは、Vehicle という名前の XML 要素生成します。ただし、Cars などの別の名前の要素必要な場合には、その名前を elementName パラメータ渡します

type パラメータ使用して基本クラスから派生する型を指定します。たとえば、MyAnimal という名前のプロパティAnimal オブジェクト返す場合想定します。このオブジェクト拡張するには、Mammal という名前の新しクラスAnimal クラスから継承して作成しますXmlSerializer に対してMyAnimal プロパティシリアル化するときに Mammal クラス受け入れるように指示するには、Mammal クラスTypeコンストラクタ渡します

使用例使用例

Instrument オブジェクト配列返すフィールド Instruments1 つ含んでいるクラス Orchestraシリアル化する例を次に示しますBrass という名前の 2 番目のクラスInstrument クラスから継承されます。この例では、XmlElementAttributeInstruments フィールド適用されBrass 型が指定されています。これにより、Instruments フィールドBrass オブジェクト受け入れるようになりますまた、ElementName プロパティ設定することによって、XML 要素の名前も指定します

Option Strict
Option Explicit

Imports System
Imports System.IO
Imports System.Xml.Serialization
Imports Microsoft.VisualBasic


Public Class Orchestra
    Public Instruments() As Instrument
End Class

Public Class Instrument
    Public Name As String
End Class

Public Class Brass
    Inherits Instrument
    Public IsValved As Boolean
End Class

Public Class Run
    
    Public Shared Sub Main()
        Dim test As New
 Run()
        test.SerializeObject("Override.xml")
        test.DeserializeObject("Override.xml")
    End Sub 'Main
    
    
    Public Sub SerializeObject(filename As
 String)
        ' To write the file, a TextWriter is required.
        Dim writer As New
 StreamWriter(filename)
        
        Dim attrOverrides As New
 XmlAttributeOverrides()
        Dim attrs As New
 XmlAttributes()
        
        ' Creates an XmlElementAttribute that overrides the Instrument
 type.
        Dim attr As New
 XmlElementAttribute(GetType(Brass))
        attr.ElementName = "Brass"
        
        ' Adds the element to the collection of elements.
        attrs.XmlElements.Add(attr)
        attrOverrides.Add(GetType(Orchestra), "Instruments",
 attrs)
        
        ' Creates the XmlSerializer using the XmlAttributeOverrides.
        Dim s As New XmlSerializer(GetType(Orchestra),
 attrOverrides)
        
        ' Creates the object to serialize.
        Dim band As New
 Orchestra()
        
        ' Creates an object of the derived type.
        Dim i As New Brass()
        i.Name = "Trumpet"
        i.IsValved = True
        Dim myInstruments() As Instrument =
 {i}
        band.Instruments = myInstruments
        s.Serialize(writer, band)
        writer.Close()
    End Sub
    
    
    Public Sub DeserializeObject(filename As
 String)
        Dim attrOverrides As New
 XmlAttributeOverrides()
        Dim attrs As New
 XmlAttributes()
        
        ' Create an XmlElementAttribute that override the Instrument
 type.
        Dim attr As New
 XmlElementAttribute(GetType(Brass))
        attr.ElementName = "Brass"
        
        ' Add the element to the collection of elements.
        attrs.XmlElements.Add(attr)
        attrOverrides.Add(GetType(Orchestra), "Instruments",
 attrs)
        
        ' Create the XmlSerializer using the XmlAttributeOverrides.
        Dim s As New XmlSerializer(GetType(Orchestra),
 attrOverrides)
        
        Dim fs As New FileStream(filename,
 FileMode.Open)
        Dim band As Orchestra = CType(s.Deserialize(fs),
 Orchestra)
        Console.WriteLine("Brass:")
        
        ' Deserializing differs from serializing. To read the
        ' derived-object values, declare an object of the derived
        ' type (Brass) and cast the Instrument instance to it. 
        Dim b As Brass
        Dim i As Instrument
        For Each i In  band.Instruments
            b = CType(i, Brass)
            Console.WriteLine((b.Name + ControlChars.Cr + b.IsValved.ToString()))
        Next i
    End Sub
End Class

using System;
using System.IO;
using System.Xml.Serialization;

public class Orchestra
{
   public Instrument[] Instruments;
}   

public class Instrument
{
   public string Name;
}

public class Brass:Instrument{
   public bool IsValved;
}

public class Run
{
    public static void Main()
    {
       Run test = new Run();
       test.SerializeObject("Override.xml");
       test.DeserializeObject("Override.xml");
    }

    public void SerializeObject(string
 filename)
    {
      // To write the file, a TextWriter is required.
      TextWriter writer = new StreamWriter(filename);
      
      XmlAttributeOverrides attrOverrides = 
         new XmlAttributeOverrides();
      XmlAttributes attrs = new XmlAttributes();

      // Creates an XmlElementAttribute that overrides the Instrument
 type.
      XmlElementAttribute attr = new 
      XmlElementAttribute(typeof(Brass));
      attr.ElementName = "Brass";

      // Adds the element to the collection of elements.
      attrs.XmlElements.Add(attr);
      attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

      // Creates the XmlSerializer using the XmlAttributeOverrides.
      XmlSerializer s = 
      new XmlSerializer(typeof(Orchestra), attrOverrides);

      // Creates the object to serialize.
      Orchestra band = new Orchestra();
      
      // Creates an object of the derived type.
      Brass i = new Brass();
      i.Name = "Trumpet";
      i.IsValved = true;
      Instrument[] myInstruments = {i};
      band.Instruments = myInstruments;
      s.Serialize(writer,band);
      writer.Close();
   }

   public void DeserializeObject(string
 filename)
   {
      XmlAttributeOverrides attrOverrides = 
         new XmlAttributeOverrides();
      XmlAttributes attrs = new XmlAttributes();

      // Creates an XmlElementAttribute that override the Instrument
 type.
      XmlElementAttribute attr = new 
      XmlElementAttribute(typeof(Brass));
      attr.ElementName = "Brass";

      // Adds the element to the collection of elements.
      attrs.XmlElements.Add(attr);
      attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

      // Creates the XmlSerializer using the XmlAttributeOverrides.
      XmlSerializer s = 
      new XmlSerializer(typeof(Orchestra), attrOverrides);

      FileStream fs = new FileStream(filename, FileMode.Open);
      Orchestra band = (Orchestra) s.Deserialize(fs);
      Console.WriteLine("Brass:");

      /* Deserializing differs from serializing. To read the 
         derived-object values, declare an object of the derived 
         type (Brass) and cast the Instrument instance to it. */
      Brass b;
      foreach(Instrument i in band.Instruments)
 
      {
         b= (Brass)i;
         Console.WriteLine(
         b.Name + "\n" + 
         b.IsValved);
      }
   }
}

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;
public ref class Instrument
{
public:
   String^ Name;
};

public ref class Brass: public
 Instrument
{
public:
   bool IsValved;
};

public ref class Orchestra
{
public:
   array<Instrument^>^Instruments;
};

void SerializeObject( String^ filename )
{
   // To write the file, a TextWriter is required.
   TextWriter^ writer = gcnew StreamWriter( filename );
   XmlAttributeOverrides^ attrOverrides = gcnew XmlAttributeOverrides;
   XmlAttributes^ attrs = gcnew XmlAttributes;

   // Creates an XmlElementAttribute that overrides the Instrument type.
   XmlElementAttribute^ attr = gcnew XmlElementAttribute( Brass::typeid );
   attr->ElementName = "Brass";

   // Adds the element to the collection of elements.
   attrs->XmlElements->Add( attr );
   attrOverrides->Add( Orchestra::typeid, "Instruments", attrs );

   // Creates the XmlSerializer using the XmlAttributeOverrides.
   XmlSerializer^ s = gcnew XmlSerializer( Orchestra::typeid,attrOverrides );

   // Creates the object to serialize.
   Orchestra^ band = gcnew Orchestra;

   // Creates an object of the derived type.
   Brass^ i = gcnew Brass;
   i->Name = "Trumpet";
   i->IsValved = true;
   array<Instrument^>^myInstruments = {i};
   band->Instruments = myInstruments;
   s->Serialize( writer, band );
   writer->Close();
}

void DeserializeObject( String^ filename )
{
   XmlAttributeOverrides^ attrOverrides = gcnew XmlAttributeOverrides;
   XmlAttributes^ attrs = gcnew XmlAttributes;

   // Creates an XmlElementAttribute that override the Instrument type.
   XmlElementAttribute^ attr = gcnew XmlElementAttribute( Brass::typeid );
   attr->ElementName = "Brass";

   // Adds the element to the collection of elements.
   attrs->XmlElements->Add( attr );
   attrOverrides->Add( Orchestra::typeid, "Instruments", attrs );

   // Creates the XmlSerializer using the XmlAttributeOverrides.
   XmlSerializer^ s = gcnew XmlSerializer( Orchestra::typeid,attrOverrides );
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   Orchestra^ band = dynamic_cast<Orchestra^>(s->Deserialize( fs ));
   Console::WriteLine( "Brass:" );

   /* Deserializing differs from serializing. To read the 
      derived-object values, declare an object of the derived 
      type (Brass) and cast the Instrument instance to it. */
   Brass^ b;
   System::Collections::IEnumerator^ myEnum = band->Instruments->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Instrument^ i = safe_cast<Instrument^>(myEnum->Current);
      b = dynamic_cast<Brass^>(i);
      Console::WriteLine( "{0}\n{1}", b->Name, b->IsValved );
   }
}

int main()
{
   SerializeObject( "Override.xml" );
   DeserializeObject( "Override.xml" );
}
import System.*;
import System.IO.*;
import System.Xml.Serialization.*;

public class Orchestra
{
    public Instrument instruments[];
} //Orchestra

public class Instrument
{
    public String name;
} //Instrument

public class Brass extends Instrument
{
    public boolean isValved;
} //Brass

public class Run
{
    public static void main(String[]
 args)
    {
        Run test = new Run();
        test.SerializeObject("Override.xml");
        test.DeserializeObject("Override.xml");
    } //main

    public void SerializeObject(String fileName)
    {
        // To write the file, a TextWriter is required.
        TextWriter writer = new StreamWriter(fileName);
        XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();
        XmlAttributes attrs = new XmlAttributes();

        // Creates an XmlElementAttribute that overrides the Instrument
 type.
        XmlElementAttribute attr =
            new XmlElementAttribute(Brass.class.ToType());
        attr.set_ElementName("Brass");

        // Adds the element to the collection of elements.
        attrs.get_XmlElements().Add(attr);
        attrOverrides.Add(Orchestra.class.ToType(), "instruments",
 attrs);

        // Creates the XmlSerializer using the XmlAttributeOverrides.
        XmlSerializer s =
            new XmlSerializer(Orchestra.class.ToType(),
 attrOverrides);

        // Creates the object to serialize.
        Orchestra band = new Orchestra();

        // Creates an object of the derived type.
        Brass i = new Brass();
        i.name = "Trumpet";
        i.isValved = true;
        Instrument myInstruments[] = { i };
        band.instruments = myInstruments;
        s.Serialize(writer, band);
        writer.Close();
    } //SerializeObject

    public void DeserializeObject(String fileName)
    {
        XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();
        XmlAttributes attrs = new XmlAttributes();

        // Creates an XmlElementAttribute that override the Instrument
 type.
        XmlElementAttribute attr =
            new XmlElementAttribute(Brass.class.ToType());
        attr.set_ElementName("Brass");

        // Adds the element to the collection of elements.
        attrs.get_XmlElements().Add(attr);
        attrOverrides.Add(Orchestra.class.ToType(), "instruments",
 attrs);

        // Creates the XmlSerializer using the XmlAttributeOverrides.
        XmlSerializer s =
            new XmlSerializer(Orchestra.class.ToType(),
 attrOverrides);
        FileStream fs = new FileStream(fileName, FileMode.Open);
        Orchestra band = (Orchestra)s.Deserialize(fs);

        Console.WriteLine("Brass:");

        /* Deserializing differs from serializing. To read the 
           derived-object values, declare an object of the derived 
           type (Brass) and cast the Instrument instance to it. */

        Brass b;
        for (int iCtr = 0; iCtr < band.instruments.length;
 iCtr++) {
            Instrument i = band.instruments[iCtr];
            b = (Brass)i;
            Console.WriteLine(b.name + "\n" + Convert.ToString(b.isValved));
        }
    } //DeserializeObject
} //Run
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlElementAttribute クラス
XmlElementAttribute メンバ
System.Xml.Serialization 名前空間

XmlElementAttribute コンストラクタ (Type)

XmlElementAttribute クラス新しインスタンス初期化しXmlElementAttribute適用先メンバの型を指定します。この型が使用されるのは、その型を含むオブジェクトを XmlSerializer がシリアル化または逆シリアル化する場合です。

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

Dim type As Type

Dim instance As New XmlElementAttribute(type)
public XmlElementAttribute (
    Type type
)
public:
XmlElementAttribute (
    Type^ type
)
public XmlElementAttribute (
    Type type
)
public function XmlElementAttribute (
    type : Type
)

パラメータ

type

メンバの型から派生したオブジェクトType

解説解説
使用例使用例

Instrument オブジェクト配列返すフィールド Instruments1 つ含んでいるクラス Orchestraシリアル化する例を次に示しますBrass という名前の 2 番目のクラスInstrument クラスから継承されます。この例では、XmlElementAttributeInstruments フィールド適用されBrass 型が指定されています。これにより、Instruments フィールドBrass オブジェクト受け入れるようになりますまた、ElementName プロパティ設定することによって、XML 要素の名前も指定します

Option Strict
Option Explicit

Imports System
Imports System.IO
Imports System.Xml.Serialization
Imports Microsoft.VisualBasic


Public Class Orchestra
    Public Instruments() As Instrument
End Class

Public Class Instrument
    Public Name As String
End Class

Public Class Brass
    Inherits Instrument
    Public IsValved As Boolean
End Class

Public Class Run
    
    Public Shared Sub Main()
        Dim test As New
 Run()
        test.SerializeObject("Override.xml")
        test.DeserializeObject("Override.xml")
    End Sub 'Main
    
    
    Public Sub SerializeObject(filename As
 String)
        ' To write the file, a TextWriter is required.
        Dim writer As New
 StreamWriter(filename)
        
        Dim attrOverrides As New
 XmlAttributeOverrides()
        Dim attrs As New
 XmlAttributes()
        
        ' Creates an XmlElementAttribute that overrides the Instrument
 type.
        Dim attr As New
 XmlElementAttribute(GetType(Brass))
        attr.ElementName = "Brass"
        
        ' Adds the element to the collection of elements.
        attrs.XmlElements.Add(attr)
        attrOverrides.Add(GetType(Orchestra), "Instruments",
 attrs)
        
        ' Creates the XmlSerializer using the XmlAttributeOverrides.
        Dim s As New XmlSerializer(GetType(Orchestra),
 attrOverrides)
        
        ' Creates the object to serialize.
        Dim band As New
 Orchestra()
        
        ' Creates an object of the derived type.
        Dim i As New Brass()
        i.Name = "Trumpet"
        i.IsValved = True
        Dim myInstruments() As Instrument =
 {i}
        band.Instruments = myInstruments
        s.Serialize(writer, band)
        writer.Close()
    End Sub
    
    
    Public Sub DeserializeObject(filename As
 String)
        Dim attrOverrides As New
 XmlAttributeOverrides()
        Dim attrs As New
 XmlAttributes()
        
        ' Create an XmlElementAttribute that override the Instrument
 type.
        Dim attr As New
 XmlElementAttribute(GetType(Brass))
        attr.ElementName = "Brass"
        
        ' Add the element to the collection of elements.
        attrs.XmlElements.Add(attr)
        attrOverrides.Add(GetType(Orchestra), "Instruments",
 attrs)
        
        ' Create the XmlSerializer using the XmlAttributeOverrides.
        Dim s As New XmlSerializer(GetType(Orchestra),
 attrOverrides)
        
        Dim fs As New FileStream(filename,
 FileMode.Open)
        Dim band As Orchestra = CType(s.Deserialize(fs),
 Orchestra)
        Console.WriteLine("Brass:")
        
        ' Deserializing differs from serializing. To read the
        ' derived-object values, declare an object of the derived
        ' type (Brass) and cast the Instrument instance to it. 
        Dim b As Brass
        Dim i As Instrument
        For Each i In  band.Instruments
            b = CType(i, Brass)
            Console.WriteLine((b.Name + ControlChars.Cr + b.IsValved.ToString()))
        Next i
    End Sub
End Class

using System;
using System.IO;
using System.Xml.Serialization;

public class Orchestra
{
   public Instrument[] Instruments;
}   

public class Instrument
{
   public string Name;
}

public class Brass:Instrument{
   public bool IsValved;
}

public class Run
{
    public static void Main()
    {
       Run test = new Run();
       test.SerializeObject("Override.xml");
       test.DeserializeObject("Override.xml");
    }

    public void SerializeObject(string
 filename)
    {
      // To write the file, a TextWriter is required.
      TextWriter writer = new StreamWriter(filename);
      
      XmlAttributeOverrides attrOverrides = 
         new XmlAttributeOverrides();
      XmlAttributes attrs = new XmlAttributes();

      // Creates an XmlElementAttribute that overrides the Instrument
 type.
      XmlElementAttribute attr = new 
      XmlElementAttribute(typeof(Brass));
      attr.ElementName = "Brass";

      // Adds the element to the collection of elements.
      attrs.XmlElements.Add(attr);
      attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

      // Creates the XmlSerializer using the XmlAttributeOverrides.
      XmlSerializer s = 
      new XmlSerializer(typeof(Orchestra), attrOverrides);

      // Creates the object to serialize.
      Orchestra band = new Orchestra();
      
      // Creates an object of the derived type.
      Brass i = new Brass();
      i.Name = "Trumpet";
      i.IsValved = true;
      Instrument[] myInstruments = {i};
      band.Instruments = myInstruments;
      s.Serialize(writer,band);
      writer.Close();
   }

   public void DeserializeObject(string
 filename)
   {
      XmlAttributeOverrides attrOverrides = 
         new XmlAttributeOverrides();
      XmlAttributes attrs = new XmlAttributes();

      // Creates an XmlElementAttribute that override the Instrument
 type.
      XmlElementAttribute attr = new 
      XmlElementAttribute(typeof(Brass));
      attr.ElementName = "Brass";

      // Adds the element to the collection of elements.
      attrs.XmlElements.Add(attr);
      attrOverrides.Add(typeof(Orchestra), "Instruments", attrs);

      // Creates the XmlSerializer using the XmlAttributeOverrides.
      XmlSerializer s = 
      new XmlSerializer(typeof(Orchestra), attrOverrides);

      FileStream fs = new FileStream(filename, FileMode.Open);
      Orchestra band = (Orchestra) s.Deserialize(fs);
      Console.WriteLine("Brass:");

      /* Deserializing differs from serializing. To read the 
         derived-object values, declare an object of the derived 
         type (Brass) and cast the Instrument instance to it. */
      Brass b;
      foreach(Instrument i in band.Instruments)
 
      {
         b= (Brass)i;
         Console.WriteLine(
         b.Name + "\n" + 
         b.IsValved);
      }
   }
}

#using <System.Xml.dll>
#using <System.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml::Serialization;
public ref class Instrument
{
public:
   String^ Name;
};

public ref class Brass: public
 Instrument
{
public:
   bool IsValved;
};

public ref class Orchestra
{
public:
   array<Instrument^>^Instruments;
};

void SerializeObject( String^ filename )
{
   // To write the file, a TextWriter is required.
   TextWriter^ writer = gcnew StreamWriter( filename );
   XmlAttributeOverrides^ attrOverrides = gcnew XmlAttributeOverrides;
   XmlAttributes^ attrs = gcnew XmlAttributes;

   // Creates an XmlElementAttribute that overrides the Instrument type.
   XmlElementAttribute^ attr = gcnew XmlElementAttribute( Brass::typeid );
   attr->ElementName = "Brass";

   // Adds the element to the collection of elements.
   attrs->XmlElements->Add( attr );
   attrOverrides->Add( Orchestra::typeid, "Instruments", attrs );

   // Creates the XmlSerializer using the XmlAttributeOverrides.
   XmlSerializer^ s = gcnew XmlSerializer( Orchestra::typeid,attrOverrides );

   // Creates the object to serialize.
   Orchestra^ band = gcnew Orchestra;

   // Creates an object of the derived type.
   Brass^ i = gcnew Brass;
   i->Name = "Trumpet";
   i->IsValved = true;
   array<Instrument^>^myInstruments = {i};
   band->Instruments = myInstruments;
   s->Serialize( writer, band );
   writer->Close();
}

void DeserializeObject( String^ filename )
{
   XmlAttributeOverrides^ attrOverrides = gcnew XmlAttributeOverrides;
   XmlAttributes^ attrs = gcnew XmlAttributes;

   // Creates an XmlElementAttribute that override the Instrument type.
   XmlElementAttribute^ attr = gcnew XmlElementAttribute( Brass::typeid );
   attr->ElementName = "Brass";

   // Adds the element to the collection of elements.
   attrs->XmlElements->Add( attr );
   attrOverrides->Add( Orchestra::typeid, "Instruments", attrs );

   // Creates the XmlSerializer using the XmlAttributeOverrides.
   XmlSerializer^ s = gcnew XmlSerializer( Orchestra::typeid,attrOverrides );
   FileStream^ fs = gcnew FileStream( filename,FileMode::Open );
   Orchestra^ band = dynamic_cast<Orchestra^>(s->Deserialize( fs ));
   Console::WriteLine( "Brass:" );

   /* Deserializing differs from serializing. To read the 
      derived-object values, declare an object of the derived 
      type (Brass) and cast the Instrument instance to it. */
   Brass^ b;
   System::Collections::IEnumerator^ myEnum = band->Instruments->GetEnumerator();
   while ( myEnum->MoveNext() )
   {
      Instrument^ i = safe_cast<Instrument^>(myEnum->Current);
      b = dynamic_cast<Brass^>(i);
      Console::WriteLine( "{0}\n{1}", b->Name, b->IsValved );
   }
}

int main()
{
   SerializeObject( "Override.xml" );
   DeserializeObject( "Override.xml" );
}
import System.*;
import System.IO.*;
import System.Xml.Serialization.*;

public class Orchestra
{
    public Instrument instruments[];
} //Orchestra

public class Instrument
{
    public String name;
} //Instrument

public class Brass extends Instrument
{
    public boolean isValved;
} //Brass

public class Run
{
    public static void main(String[]
 args)
    {
        Run test = new Run();
        test.SerializeObject("Override.xml");
        test.DeserializeObject("Override.xml");
    } //main

    public void SerializeObject(String fileName)
    {
        // To write the file, a TextWriter is required.
        TextWriter writer = new StreamWriter(fileName);
        XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();
        XmlAttributes attrs = new XmlAttributes();

        // Creates an XmlElementAttribute that overrides the Instrument
 type.
        XmlElementAttribute attr =
            new XmlElementAttribute(Brass.class.ToType());
        attr.set_ElementName("Brass");

        // Adds the element to the collection of elements.
        attrs.get_XmlElements().Add(attr);
        attrOverrides.Add(Orchestra.class.ToType(), "instruments",
 attrs);

        // Creates the XmlSerializer using the XmlAttributeOverrides.
        XmlSerializer s =
            new XmlSerializer(Orchestra.class.ToType(),
 attrOverrides);

        // Creates the object to serialize.
        Orchestra band = new Orchestra();

        // Creates an object of the derived type.
        Brass i = new Brass();
        i.name = "Trumpet";
        i.isValved = true;
        Instrument myInstruments[] = { i };
        band.instruments = myInstruments;
        s.Serialize(writer, band);
        writer.Close();
    } //SerializeObject

    public void DeserializeObject(String fileName)
    {
        XmlAttributeOverrides attrOverrides = new XmlAttributeOverrides();
        XmlAttributes attrs = new XmlAttributes();

        // Creates an XmlElementAttribute that override the Instrument
 type.
        XmlElementAttribute attr =
            new XmlElementAttribute(Brass.class.ToType());
        attr.set_ElementName("Brass");

        // Adds the element to the collection of elements.
        attrs.get_XmlElements().Add(attr);
        attrOverrides.Add(Orchestra.class.ToType(), "instruments",
 attrs);

        // Creates the XmlSerializer using the XmlAttributeOverrides.
        XmlSerializer s =
            new XmlSerializer(Orchestra.class.ToType(),
 attrOverrides);
        FileStream fs = new FileStream(fileName, FileMode.Open);
        Orchestra band = (Orchestra)s.Deserialize(fs);

        Console.WriteLine("Brass:");

        /* Deserializing differs from serializing. To read the 
           derived-object values, declare an object of the derived 
           type (Brass) and cast the Instrument instance to it. */

        Brass b;
        for (int iCtr = 0; iCtr < band.instruments.length;
 iCtr++) {
            Instrument i = band.instruments[iCtr];
            b = (Brass)i;
            Console.WriteLine(b.name + "\n" + Convert.ToString(b.isValved));
        }
    } //DeserializeObject
} //Run
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlElementAttribute クラス
XmlElementAttribute メンバ
System.Xml.Serialization 名前空間

XmlElementAttribute コンストラクタ (String)

XML 要素の名前を指定して、XmlElementAttribute クラス新しインスタンス初期化します。

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

Public Sub New ( _
    elementName As String _
)
Dim elementName As String

Dim instance As New XmlElementAttribute(elementName)
public XmlElementAttribute (
    string elementName
)
public:
XmlElementAttribute (
    String^ elementName
)
public XmlElementAttribute (
    String elementName
)
public function XmlElementAttribute (
    elementName : String
)

パラメータ

elementName

シリアル化されたメンバXML 要素名。

解説解説

既定では、XmlSerializer でクラスインスタンスシリアル化するときは、メンバ名が XML 要素名として使用されます。たとえば、Vehicle という名前のフィールドは、Vehicle という名前の XML 要素生成します。ただし、Cars などの別の名前の要素必要な場合には、その名前を elementName パラメータ渡します

使用例使用例

Vehicles という名前のフィールド1 つある単純なクラスの例を次に示します。この例では、XmlElementAttributeフィールド適用しelementName パラメータ指定してます。これにより、XmlSerializer に対して、"Vehicles" ではなく "Cars" という名前で XML 要素生成するように指示できます

public class Transportation
{
    /** @attribute XmlElement("Cars")
     */
    public String vehicles;
} //Transportation
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
XmlElementAttribute クラス
XmlElementAttribute メンバ
System.Xml.Serialization 名前空間

XmlElementAttribute コンストラクタ

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

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

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

XmlElementAttribute (String) XML 要素の名前を指定してXmlElementAttribute クラス新しインスタンス初期化します。

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

XmlElementAttribute (Type) XmlElementAttribute クラス新しインスタンス初期化しXmlElementAttribute適用先メンバの型を指定します。この型が使用されるのは、その型を含むオブジェクトを XmlSerializer がシリアル化または逆シリアル化する場合です。

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

XmlElementAttribute (String, Type) XmlElementAttribute新しインスタンス初期化しXmlElementAttribute適用先であるメンバXML 要素の名前と派生型指定します。このメンバ型が使用されるのは、その型を含むオブジェクトXmlSerializerシリアル化する場合です。

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

参照参照

関連項目

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

XmlElementAttribute プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。 ( Attribute から継承されます。)
参照参照

関連項目

XmlElementAttribute クラス
System.Xml.Serialization 名前空間
XmlArrayAttribute クラス
XmlAttributeOverrides クラス
XmlAttributes クラス
XmlElementAttributes
XmlAttributes.XmlElements プロパティ
XmlRootAttribute
XmlSerializer
XmlAttributes クラス

その他の技術情報

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

XmlElementAttribute メソッド


パブリック メソッドパブリック メソッド

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

関連項目

XmlElementAttribute クラス
System.Xml.Serialization 名前空間
XmlArrayAttribute クラス
XmlAttributeOverrides クラス
XmlAttributes クラス
XmlElementAttributes
XmlAttributes.XmlElements プロパティ
XmlRootAttribute
XmlSerializer
XmlAttributes クラス

その他の技術情報

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

XmlElementAttribute メンバ

パブリック フィールドパブリック プロパティ保持するオブジェクトを XmlSerializer がシリアル化または逆シリアル化するときに、それらのフィールドプロパティXML 要素を表すかどうか示します

XmlElementAttribute データ型公開されるメンバを以下の表に示します


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド XmlElementAttribute オーバーロードされます。 XmlElementAttribute クラス新しインスタンス初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート .NET Compact Framework によるサポート TypeId  派生クラス実装されている場合は、この Attribute一意識別子取得します。(Attribute から継承されます。)
パブリック メソッドパブリック メソッド
( プロテクト メソッド参照)
  名前 説明
パブリック メソッド Equals  オーバーロードされます。 ( Attribute から継承されます。)
パブリック メソッド GetCustomAttribute  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用され指定した型のカスタム属性取得します。 (Attribute から継承されます。)
パブリック メソッド GetCustomAttributes  オーバーロードされますアセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されカスタム属性配列取得します。 (Attribute から継承されます。)
パブリック メソッド GetHashCode  このインスタンスハッシュ コード返します。 (Attribute から継承されます。)
パブリック メソッド GetType  現在のインスタンスType取得します。 (Object から継承されます。)
パブリック メソッド IsDefaultAttribute  派生クラス内でオーバーライドされたときに、このインスタンスの値が派生クラス既定値かどうか示します。 (Attribute から継承されます。)
パブリック メソッド IsDefined  オーバーロードされます指定した型のカスタム属性が、アセンブリモジュール、型のメンバ、またはメソッド パラメータ適用されているかどうか判断します。 (Attribute から継承されます。)
パブリック メソッド Match  派生クラス内でオーバーライドされたときに、指定したオブジェクトとこのインスタンス等しかどうかを示す値を返します。 (Attribute から継承されます。)
パブリック メソッド ReferenceEquals  指定した複数Object インスタンス同一かどうか判断します。 (Object から継承されます。)
パブリック メソッド ToString  現在の Object を表す String返します。 (Object から継承されます。)
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

XmlElementAttribute クラス
System.Xml.Serialization 名前空間
XmlArrayAttribute クラス
XmlAttributeOverrides クラス
XmlAttributes クラス
XmlElementAttributes
XmlAttributes.XmlElements プロパティ
XmlRootAttribute
XmlSerializer
XmlAttributes クラス

その他の技術情報

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



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

辞書ショートカット

すべての辞書の索引

「XmlElementAttribute」の関連用語

XmlElementAttributeのお隣キーワード
検索ランキング

   

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



XmlElementAttributeのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

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

©2025 GRAS Group, Inc.RSS