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.

Namespace:  System.Xml.Serialization
Assembly:  System.Xml (in System.Xml.dll)

public string ElementName { get; set; }

Property Value

Type: System.String
The name of the generated XML element. The default is the member identifier.

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

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.


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;
}



.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Community Additions

Show:
© 2014 Microsoft