XmlArrayAttribute Class

May 11, 2014

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

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

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

[AttributeUsageAttribute(AttributeTargets.Field|AttributeTargets.Parameter|AttributeTargets.Property|AttributeTargets.ReturnValue, AllowMultiple = false)]
public class XmlArrayAttribute : Attribute

The XmlArrayAttribute type exposes the following members.

  NameDescription
Public methodXmlArrayAttribute()Initializes a new instance of the XmlArrayAttribute class.
Public methodXmlArrayAttribute(String)Initializes a new instance of the XmlArrayAttribute class and specifies the XML element name generated in the XML document instance.
Top

  NameDescription
Public propertyElementNameGets or sets the XML element name given to the serialized array.
Public propertyFormGets or sets a value that indicates whether the XML element name generated by the XmlSerializer is qualified or unqualified.
Public propertyIsNullableGets 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.
Public propertyNamespaceGets or sets the namespace of the XML element.
Public propertyOrderGets or sets the explicit order in which the elements are serialized or deserialized.
Top

  NameDescription
Public methodEqualsInfrastructure. Returns a value that indicates whether this instance is equal to a specified object. (Inherited from Attribute.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeReturns the hash code for this instance. (Inherited from Attribute.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodMatchWhen overridden in a derived class, returns a value that indicates whether this instance equals a specified object. (Inherited from Attribute.)
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

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.

NoteNote:

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

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

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

Show:
© 2014 Microsoft