XmlArrayItemAttribute.ElementName Właściwość

Definicja

Pobiera lub ustawia nazwę wygenerowanego elementu 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

Wartość właściwości

Nazwa wygenerowanego elementu XML. Wartość domyślna to identyfikator elementu członkowskiego.

Przykłady

W poniższym przykładzie ustawiono ElementName właściwość dla Vehicle klasy i Car , zmieniając nazwy elementów XML generowanych XmlSerializer dla tych klas.

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

Uwagi

Określ, ElementName czy chcesz, aby nazwa wygenerowanego elementu XML różniła się od identyfikatora elementu członkowskiego.

Możesz ustawić tę samą ElementName wartość na więcej niż jedną składową klasy, jeśli wygenerowany dokument XML używa przestrzeni nazw XML do odróżnienia identycznych nazwanych składowych. Aby uzyskać szczegółowe informacje na temat używania przestrzeni nazw i nazw prefiksów w dokumencie XML, zobacz klasę XmlSerializerNamespaces .

Dotyczy