Compartilhar via


XmlAttributeAttribute Class

Microsoft Silverlight will reach end of support after October 2021. Learn more.

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

Inheritance Hierarchy

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

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

Syntax

'Declaration
<AttributeUsageAttribute(AttributeTargets.Property Or AttributeTargets.Field Or AttributeTargets.Parameter Or AttributeTargets.ReturnValue)> _
Public Class XmlAttributeAttribute _
    Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Property|AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.ReturnValue)]
public class XmlAttributeAttribute : Attribute

The XmlAttributeAttribute type exposes the following members.

Constructors

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 XmlAttributeAttribute() Initializes a new instance of the XmlAttributeAttribute class.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 XmlAttributeAttribute(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 360 XmlAttributeAttribute(Type) Initializes a new instance of the XmlAttributeAttribute class.
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 XmlAttributeAttribute(String, Type) Initializes a new instance of the XmlAttributeAttribute class.

Top

Properties

  Name Description
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 AttributeName Gets or sets the name of the XML attribute.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 DataType Gets or sets the XSD data type of the XML attribute generated by the XmlSerializer.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Form Gets 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 360 Namespace Gets or sets the XML namespace of the XML attribute.
Public propertySupported by Silverlight for Windows PhoneSupported by Xbox 360 Type Gets or sets the complex type of the XML attribute.

Top

Methods

  Name Description
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Equals Infrastructure. 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 360 Finalize Allows 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 360 GetHashCode Returns the hash code for this instance. (Inherited from Attribute.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 GetType Gets the Type of the current instance. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 Match When 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 360 MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by Silverlight for Windows PhoneSupported by Xbox 360 ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

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.

Version Information

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

Platforms

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

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.