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 요소의 이름입니다. 기본값은 멤버 식별자입니다.

예제

다음 예제에서는 및 클래스에 대 한 VehicleCar 속성을 설정 ElementName 하 여 해당 클래스에 대해 생성 하는 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 참조하세요.

적용 대상