This documentation is archived and is not being maintained.

XmlAttributes.XmlEnum Property

Gets or sets an object that specifies how the XmlSerializer serializes an enumeration member.

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

public function get XmlEnum () : XmlEnumAttribute 
public function set XmlEnum (value : XmlEnumAttribute)

Property Value

Type: System.Xml.Serialization.XmlEnumAttribute
An XmlEnumAttribute that specifies how the XmlSerializer serializes an enumeration member.

For each identifier you want to override, you must create an XmlAttributes object, and set the XmlEnum property to an XmlEnumAttribute that overrides the identifier. Add the XmlAttributes object to the XmlAttributeOverrides object and specify both the Type of the class that contains the enumeration, and the overridden member name.

The following example serializes two classes named Food and FoodType. The FoodType class contains two enumerations that are overridden and, for each enumeration, the example creates an XmlEnumAttribute object that it assigns to the XmlEnum property of an XmlAttributes object. The example then adds the XmlAttributes object to an XmlAttributeOverrides object, which is used to create an XmlSerializer.

No code example is currently available or this language may not be supported.
#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::IO;
using namespace System::Xml;
using namespace System::Xml::Serialization;

public __value enum FoodType
   // Subsequent code overrides these enumerations.

// This is the class that will be serialized.
public __gc class Food
   FoodType Type;

// Return an XmlSerializer used for overriding. 
XmlSerializer* CreateOverrider()
   // Create the XmlAttributeOverrides and XmlAttributes objects.
   XmlAttributeOverrides* xOver = new XmlAttributeOverrides();
   XmlAttributes* xAttrs = new XmlAttributes();

   // Add an XmlEnumAttribute for the FoodType.Low enumeration.
   XmlEnumAttribute* xEnum = new XmlEnumAttribute();
   xEnum->Name = S"Cold";
   xAttrs->XmlEnum = xEnum;
   xOver->Add(__typeof(FoodType), S"Low", xAttrs);

   // Add an XmlEnumAttribute for the FoodType.High enumeration.
   xAttrs = new XmlAttributes();
   xEnum = new XmlEnumAttribute();
   xEnum->Name = S"Hot";
   xAttrs->XmlEnum = xEnum;
   xOver->Add(__typeof(FoodType), S"High", xAttrs);

   // Create the XmlSerializer, and return it.
   return new XmlSerializer(__typeof(Food), xOver);

void SerializeObject(String* filename)
   // Create an instance of the XmlSerializer class.
   XmlSerializer* mySerializer =  CreateOverrider();
   // Writing the file requires a TextWriter.
   TextWriter* writer = new StreamWriter(filename);

   // Create an instance of the class that will be serialized.
   Food* myFood = new Food();

   // Set the object properties.
   myFood->Type = FoodType::High;

   // Serialize the class, and close the TextWriter.
   mySerializer->Serialize(writer, myFood);

void DeserializeObject(String* filename)
   XmlSerializer* mySerializer = CreateOverrider();
   FileStream* fs = new FileStream(filename, FileMode::Open);
   Food* myFood = dynamic_cast<Food*>(mySerializer->Deserialize(fs));


int main()

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

XNA Framework

Supported in: 3.0, 2.0, 1.0