Specifies that the System.Xml.Serialization.XmlSerializer must serialize the class member as an XML attribute.
See Also: XmlAttributeAttribute Members
The System.Xml.Serialization.XmlAttributeAttribute belongs to a family of attributes that controls how the System.Xml.Serialization.XmlSerializer serializes, or deserializes, an object. For a complete list of similar attributes, see Attributes That Control XML Serialization.
When applied to a public field or property, the System.Xml.Serialization.XmlAttributeAttribute informs the System.Xml.Serialization.XmlSerializer to serialize the member as an XML attribute. By default, the System.Xml.Serialization.XmlSerializer serializes public fields and properties as XML elements.
You can assign the System.Xml.Serialization.XmlAttributeAttribute only to public fields or public properties that return a value (or array of values) that can be mapped to one of the XML Schema definition language (XSD) simple types (including all built-in datatypes derived from the XSD anySimpleType type). The possible types include any that can be mapped to the XSD simple types, including Guid, char, and enumerations. See the XmlAttributeAttribute.DataType property for a list of XSD types and how they are mapped to.NET data types.
There are two special attributes that can be set with the System.Xml.Serialization.XmlAttributeAttribute : the xml:lang (specifies language) and xml:space (specifies how to handle white space) attributes. These attributes are intended to convey information that is relevant only to an application processing the XML. Examples of setting these are shown in the following code.
Example
[XmlAttribute("xml:lang")] public string Lang; // Set this to 'default' or 'preserve'. [XmlAttribute("space", Namespace = "http://www.w3.org/XML/1998/namespace")] public string Space [Visual Basic] <XmlAttribute("xml:lang")> _ Public Lang As String ' Set this to 'default' or 'preserve'. <XmlAttribute("space", _ Namespace:= "http://www.w3.org/XML/1998/namespace")> _ Public Space As String
For more information about using attributes, see Extending Metadata Using Attributes.
You can use the word XmlAttribute in your code instead of the longer System.Xml.Serialization.XmlAttributeAttribute.