Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

XmlAttributeAttribute Class

Specifies that the XmlSerializer must serialize the class member as an XML attribute.

System.Object
  System.Attribute
    System.Xml.Serialization.XmlAttributeAttribute

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

[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue)]
public class XmlAttributeAttribute : Attribute

The XmlAttributeAttribute type exposes the following members.

  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360XmlAttributeAttribute()Initializes a new instance of the XmlAttributeAttribute class.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360XmlAttributeAttribute(String)Initializes a new instance of the XmlAttributeAttribute class and specifies the name of the generated XML attribute.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360XmlAttributeAttribute(Type)Initializes a new instance of the XmlAttributeAttribute class.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360XmlAttributeAttribute(String, Type)Initializes a new instance of the XmlAttributeAttribute class.
Top

  NameDescription
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360AttributeNameGets or sets the name of the XML attribute.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360DataTypeGets or sets the XSD data type of the XML attribute generated by the XmlSerializer.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360FormGets or sets a value that indicates whether the XML attribute name generated by the XmlSerializer is qualified.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360NamespaceGets or sets the XML namespace of the XML attribute.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360TypeGets or sets the complex type of the XML attribute.
Top

  NameDescription
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360EqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360FinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360GetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected methodSupported by Silverlight for Windows PhoneSupported by Xbox 360MemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360ToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The XmlAttributeAttribute belongs to a family of attributes that controls how the XmlSerializer serializes or deserializes an object.

When applied to a public field or property, the XmlAttributeAttribute informs the XmlSerializer to serialize the member as an XML attribute. By default, the XmlSerializer serializes public fields and properties as XML elements.

You can assign the 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 (XSD) language simple types (including all built-in data types 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 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 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 that is processing the XML. Examples of setting these are shown in the following code.


[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

NoteNote:

You can use the word XmlAttribute in your code instead of the longer XmlAttributeAttribute.

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

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

Community Additions

Show:
© 2014 Microsoft