Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XmlArrayItemAttribute.ElementName Property

Gets or sets the name of the generated XML element.

[Visual Basic]
Public Property ElementName As String
[C#]
public string ElementName {get; set;}
[C++]
public: __property String* get_ElementName();
public: __property void set_ElementName(String*);
[JScript]
public function get ElementName() : String;
public function set ElementName(String);

Property Value

The name of the generated XML element. The default is the member identifier.

Remarks

Specify an ElementName if you want the name of the generated XML element to differ from the member's identifier.

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. For details on how to use namespaces and prefixed names in the XML document, see the XmlSerializerNamespaces class.

Example

[Visual Basic, C#, C++] 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.

[Visual Basic] 
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


[C#] 
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;
}


[C++] 
// By default, this class results in XML elements named "Vehicle". 
public __gc class Vehicle
{
public:
   String* id;
};

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

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

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

XmlArrayItemAttribute Class | XmlArrayItemAttribute Members | System.Xml.Serialization Namespace

Show:
© 2014 Microsoft