This documentation is archived and is not being maintained.

XmlEnumAttribute Class

Controls how the XmlSerializer serializes an enumeration member.

For a list of all members of this type, see XmlEnumAttribute Members.


[Visual Basic]
Public Class XmlEnumAttribute
   Inherits Attribute
public class XmlEnumAttribute : Attribute
public __gc class XmlEnumAttribute : public Attribute
class XmlEnumAttribute extends Attribute

Thread Safety

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


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.

Note   In your code you can use the word XmlEnum instead of the longer XmlEnumAttribute.


[Visual Basic, C#, C++] The following example applies the XmlEnumAttribute to the members of an enumeration. When the XmlSerializer generates XML data for this enumeration, the data will conform to the values of the Name properties.

[Visual Basic] 
Public Enum EmployeeStatus
   <XmlEnum("Single")> One = 1
   <XmlEnum("Double")> Two = 2
   <XmlEnum("Triple")> Three = 3
End Enum

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")]
[Visual Basic, C#, C++] Note   In your code, you can use the word XmlEnum instead of the longer XmlEnumAttribute.

[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.


Namespace: System.Xml.Serialization

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

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

See Also

XmlEnumAttribute Members | System.Xml.Serialization Namespace | Serialize | Deserialize | XmlSerializer | XmlEnum | XmlAttributeOverrides | XmlAttributes | Introducing XML Serialization | Overriding XML Serialization | XmlAttributes | Controlling XML Serialization Using Attributes | Examples of XML Serialization