XmlArrayItemAttribute.ElementName プロパティ

定義

生成された XML 要素の名前を取得または設定します。

public:
 property System::String ^ ElementName { System::String ^ get(); void set(System::String ^ value); };
public string ElementName { get; set; }
member this.ElementName : string with get, set
Public Property ElementName As String

プロパティ値

生成された XML 要素の名前。 既定値はメンバー識別子です。

次の例では、 ElementName クラスと Car クラスの プロパティをVehicle設定します。これにより、 によってこれらのクラスに対して生成される XmlSerializer XML 要素の名前が変更されます。

// By default, this class results in XML elements named "Vehicle". 
public ref class Vehicle
{
public:
   String^ id;
};

// By default, this class results in XML elements named "Car". 
public ref class Car: public Vehicle
{
public:
   String^ Maker;
};

public ref class Transportation
{
public:

   /* Specifies acceptable types and the ElementName generated 
         for each object type. */

   [XmlArray("Vehicles")]
   [XmlArrayItem(Vehicle::typeid,ElementName="Transport"),
   XmlArrayItem(Car::typeid,ElementName="Automobile")]
   array<Vehicle^>^MyVehicles;
};
public class Transportation
{
   [XmlArray("Vehicles")]
   /* Specifies acceptable types and the ElementName generated
      for each object type. */
   [XmlArrayItem(typeof(Vehicle), ElementName = "Transport"),
   XmlArrayItem(typeof(Car), ElementName = "Automobile")]
   public Vehicle[] MyVehicles;
}

// By default, this class results in XML elements named "Vehicle".
public class Vehicle
{
   public string id;
}

// By default, this class results in XML elements named "Car".
public class Car:Vehicle
{
   public string Maker;
}
Public Class Transportation
    ' Specifies acceptable types and the ElementName generated
    '  for each object type. 
    <XmlArray("Vehicles"), _
     XmlArrayItem(GetType(Vehicle), ElementName := "Transport"), _
     XmlArrayItem(GetType(Car), ElementName := "Automobile")> _
    Public MyVehicles() As Vehicle
End Class

' By default, this class results in XML elements named "Vehicle". 
Public Class Vehicle
    Public id As String
End Class

' By default, this class results in XMl elements named "Car". 
Public Class Car
    Inherits Vehicle
    Public Maker As String
End Class

注釈

ElementName生成された XML 要素の名前がメンバーの識別子と異なる場合は、 を指定します。

生成された XML ドキュメントで XML 名前空間を使用して同じ名前のメンバーを区別する場合は、同じ ElementName 値を複数のクラス メンバーに設定できます。 XML ドキュメントで名前空間とプレフィックス付き名前を使用する方法の詳細については、 クラスを XmlSerializerNamespaces 参照してください。

適用対象