This documentation is archived and is not being maintained.

XmlEnumAttribute Class

Controls how the XmlSerializer serializes an enumeration member.

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

public class XmlEnumAttribute : Attribute

The XmlEnumAttribute belongs to a family of attributes that controls how the XmlSerializer serializes or deserializes an object. For a complete list of similar attributes, see Attributes That Control XML Serialization.

Use the XmlEnumAttribute to change the enumeration that the XmlSerializer generates or recognizes (when it serializes or deserializes a class, respectively). For example, if an enumeration contains a member named One, but you prefer that the XML output be named Single, apply the XmlEnumAttribute to the enumeration member and set the Name property to "Single".

You can override the Name property value of an XmlEnumAttribute by creating an instance of the XmlEnumAttribute class and assigning it to the XmlEnum property of an XmlAttributes object. For details, see the XmlAttributeOverrides class.


You can use the word XmlEnum in your code instead of the longer XmlEnumAttribute.

The following example applies the XmlEnumAttribute to the members of an enumeration. When the XmlSerializer generates XML data for this enumeration, the data conforms to the values of the Name properties.

public enum EmployeeStatus
   [XmlEnum(Name = "Single")]
   [XmlEnum(Name = "Double")]
   [XmlEnum(Name = "Triple")]
public __value enum EmployeeStatus
   [XmlEnum(Name = S"Single")]
   [XmlEnum(Name = S"Double")]
   [XmlEnum(Name = S"Triple")]

You can use the word XmlEnum in your code instead of the longer XmlEnumAttribute.


Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

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

.NET Framework

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

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0