XmlArrayAttribute Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Specifies that the XmlSerializer must serialize a particular class member as an array of XML elements.

Inheritance Hierarchy

System..::.Object
System..::.Attribute
System.Xml.Serialization..::.XmlArrayAttribute

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

Syntax

<AttributeUsageAttribute(AttributeTargets.Field Or AttributeTargets.Parameter Or AttributeTargets.Property Or AttributeTargets.ReturnValue, AllowMultiple := False)> _
Public Class XmlArrayAttribute _
    Inherits Attribute
[AttributeUsageAttribute(AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.Property|AttributeTargets.ReturnValue, AllowMultiple = false)]
public class XmlArrayAttribute : Attribute

The XmlArrayAttribute type exposes the following members.

Constructors

Name Description
XmlArrayAttribute()()() Initializes a new instance of the XmlArrayAttribute class.
XmlArrayAttribute(String) Initializes a new instance of the XmlArrayAttribute class and specifies the XML element name generated in the XML document instance.

Top

Properties

Name Description
ElementName Gets or sets the XML element name given to the serialized array.
Form Gets or sets a value that indicates whether the XML element name generated by the XmlSerializer is qualified or unqualified.
IsNullable Gets or sets a value that indicates whether the XmlSerializer must serialize a member as an empty XML element with the xsi:nil attribute set to true.
Namespace Gets or sets the namespace of the XML element.
Order Gets or sets the explicit order in which the elements are serialized or deserialized.

Top

Methods

Name Description
Equals Infrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
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.)
GetHashCode Returns the hash code for this instance. (Inherited from Attribute.)
GetType Gets the Type of the current instance. (Inherited from Object.)
Match When overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

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

You can apply the XmlArrayAttribute to a public field or read/write property that returns an array of objects, a collection, or any class that implements the IEnumerable interface.

When you apply the XmlArrayAttribute to a class member, the Serialize method of the XmlSerializer class generates a nested sequence of XML elements from that member. An XML schema document (an .xsd file) indicates such an array as a complexType. For example, if the class to be serialized represents a purchase order, you can generate an array of purchased items by applying the XmlArrayAttribute to a public field that returns an array of objects that represent order items.

If no attributes are applied to a public field or property that returns an array of complex or primitive type objects, the XmlSerializer generates a nested sequence of XML elements by default. To more precisely control what XML elements are generated, apply an XmlArrayItemAttribute and an XmlArrayAttribute to the field or property. For example, by default, the name of the generated XML element is derived from the member identifier. You can change the name of the generated XML element by setting the ElementName property.

If you serialize an array that contains items of a specific type and all the classes derived from that type, you must use the XmlArrayItemAttribute to declare each of the types.

Note

You can use XmlArray in your code instead of the longer XmlArrayAttribute.

Version Information

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Platforms

Windows Phone

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.

See Also

Reference

System.Xml.Serialization Namespace

XmlArray

XmlArrayItemAttribute

XmlAttributeOverrides

XmlAttributes