Windows apps
Collapse the table of content
Expand the table of content
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
   /* 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;

Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Return to top
© 2017 Microsoft