XmlArrayItemAttribute.ElementName Propriété

Définition

Obtient ou définit le nom de l'élément XML généré.Gets or sets the name of the generated XML element.

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

Valeur de propriété

Nom de l'élément XML généré.The name of the generated XML element. Par défaut, il s'agit de l'identificateur du membre.The default is the member identifier.

Exemples

L’exemple suivant définit la propriété ElementName pour la classe Vehicle et Car, ce qui modifie les noms des éléments XML générés par l' XmlSerializer pour ces classes.The following example sets the ElementName property for the Vehicle and Car class--thereby changing the names of XML elements that the XmlSerializer generates for those classes.

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

Remarques

Spécifiez une ElementName si vous souhaitez que le nom de l’élément XML généré soit différent de l’identificateur du membre.Specify an ElementName if you want the name of the generated XML element to differ from the member's identifier.

Vous pouvez définir la même ElementName valeur sur plusieurs membres de classe si le document XML généré utilise des espaces de noms XML pour faire la distinction entre les membres portant le même nom.You can set the same ElementName value to more than one class member if the generated XML document uses XML namespaces to distinguish between identically named members. Pour plus d’informations sur l’utilisation des espaces de noms et des noms préfixés dans le document XML, consultez la classe XmlSerializerNamespaces.For details about how to use namespaces and prefixed names in the XML document, see the XmlSerializerNamespaces class.

S’applique à