XmlEnumAttribute Class
Assembly: System.Xml (in system.xml.dll)
'Declaration <AttributeUsageAttribute(AttributeTargets.Field)> _ Public Class XmlEnumAttribute Inherits Attribute 'Usage Dim instance As XmlEnumAttribute
/** @attribute AttributeUsageAttribute(AttributeTargets.Field) */ public class XmlEnumAttribute extends Attribute
AttributeUsageAttribute(AttributeTargets.Field) public class XmlEnumAttribute extends Attribute
Not applicable.
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: |
|---|
| 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("Single")> One = 1 <XmlEnum("Double")> Two = 2 <XmlEnum("Triple")> Three = 3 End Enum
public class EmployeeStatus
{
/** @attribute XmlEnum(Name = "Single")
*/
public static int one;
/** @attribute XmlEnum(Name = "Double")
*/
public static int two;
/** @attribute XmlEnum(Name = "Triple")
*/
public static int three;
} //EmployeeStatus
Note: |
|---|
| You can use the word XmlEnum in your code instead of the longer XmlEnumAttribute. |
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.Reference
XmlEnumAttribute MembersSystem.Xml.Serialization Namespace
Serialize
Deserialize
XmlSerializer
XmlAttributes.XmlEnum Property
XmlAttributeOverrides
XmlAttributes
Other Resources
Introducing XML SerializationHow to: Specify an Alternate Element Name for an XML Stream
Controlling XML Serialization Using Attributes
Examples of XML Serialization
XML Schema Definition Tool (Xsd.exe)
Note: