XmlArrayItemAttribute.ElementName Özellik

Tanım

Oluşturulan XML öğesinin adını alır veya ayarlar.

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

Özellik Değeri

String

Oluşturulan XML öğesinin adı. Varsayılan, üye tanımlayıcıdır.

Örnekler

Aşağıdaki örnek, ve Car sınıfının özelliğini Vehicle ayarlarElementName; böylece bu sınıflar için oluşturduğu XML öğelerinin XmlSerializer adlarını değiştirir.

// 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

Açıklamalar

Oluşturulan XML öğesinin adının üyenin tanımlayıcısından farklı olmasını istiyorsanız belirtin ElementName .

Oluşturulan XML belgesinde aynı adlı üyeler arasında ayrım yapmak için XML ad alanları kullanılıyorsa, aynı ElementName değeri birden fazla sınıf üyesine ayarlayabilirsiniz. XML belgesinde ad alanlarını ve ön ekli adları kullanma hakkında ayrıntılı bilgi için sınıfına XmlSerializerNamespaces bakın.

Şunlara uygulanır