XmlElementAttribute Constructor (String)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Initializes a new instance of the XmlElementAttribute class and specifies the name of the XML element.

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

public XmlElementAttribute(
	string elementName


Type: System.String

The XML element name of the serialized member.

By default, the XmlSerializer uses the member name as the XML element name when serializing a class instance. For example, a field named Vehicle generates an XML element named Vehicle. However if you need a different element, such as Cars, pass it in the elementName parameter.

The following example shows a simple class that contains a single field named Vehicles. The example applies the XmlElementAttribute to the field and includes the elementName parameter, thereby instructing the XmlSerializer to generate XML elements named "Cars" rather than "Vehicles".

public class Transportation
   public string Vehicles;

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