Permalink
Fetching contributors…
Cannot retrieve contributors at this time
62 lines (55 sloc) 5.39 KB
title ms.custom ms.date ms.prod ms.reviewer ms.suite ms.tgt_pltfrm ms.topic dev_langs helpviewer_keywords ms.assetid caps.latest.revision author ms.author manager
Attributes That Control XML Serialization
03/30/2017
.net
article
VB
CSharp
C++
jsharp
classes, serializing
XmlSerializer class, serializing
XML serialization, attributes
attributes [.NET Framework], XML serialization
serialization, attributes
XML Schema, serializing
414b820f-a696-4206-b576-2711d85490c7
7
Erikre
erikre
erikre

Attributes That Control XML Serialization

You can apply the attributes in the following table to classes and class members to control the way in which the xref:System.Xml.Serialization.XmlSerializer serializes or deserializes an instance of the class. To understand how these attributes control XML serialization, see Controlling XML Serialization Using Attributes.

These attributes can also be used to control the literal style SOAP messages generated by an XML Web service. For more information about applying these attributes to an XML Web services method, see XML Serialization with XML Web Services.

For more information about attributes, see Attributes.

Attribute Applies to Specifies
xref:System.Xml.Serialization.XmlAnyAttributeAttribute Public field, property, parameter, or return value that returns an array of xref:System.Xml.XmlAttribute objects. When deserializing, the array will be filled with xref:System.Xml.XmlAttribute objects that represent all XML attributes unknown to the schema.
xref:System.Xml.Serialization.XmlAnyElementAttribute Public field, property, parameter, or return value that returns an array of xref:System.Xml.XmlElement objects. When deserializing, the array is filled with xref:System.Xml.XmlElement objects that represent all XML elements unknown to the schema.
xref:System.Xml.Serialization.XmlArrayAttribute Public field, property, parameter, or return value that returns an array of complex objects. The members of the array will be generated as members of an XML array.
xref:System.Xml.Serialization.XmlArrayItemAttribute Public field, property, parameter, or return value that returns an array of complex objects. The derived types that can be inserted into an array. Usually applied in conjunction with an xref:System.Xml.Serialization.XmlArrayAttribute.
xref:System.Xml.Serialization.XmlAttributeAttribute Public field, property, parameter, or return value. The member will be serialized as an XML attribute.
xref:System.Xml.Serialization.XmlChoiceIdentifierAttribute Public field, property, parameter, or return value. The member can be further disambiguated by using an enumeration.
xref:System.Xml.Serialization.XmlElementAttribute Public field, property, parameter, or return value. The field or property will be serialized as an XML element.
xref:System.Xml.Serialization.XmlEnumAttribute Public field that is an enumeration identifier. The element name of an enumeration member.
xref:System.Xml.Serialization.XmlIgnoreAttribute Public properties and fields. The property or field should be ignored when the containing class is serialized.
xref:System.Xml.Serialization.XmlIncludeAttribute Public derived class declarations, and return values of public methods for Web Services Description Language (WSDL) documents. The class should be included when generating schemas (to be recognized when serialized).
xref:System.Xml.Serialization.XmlRootAttribute Public class declarations. Controls XML serialization of the attribute target as an XML root element. Use the attribute to further specify the namespace and element name.
xref:System.Xml.Serialization.XmlTextAttribute Public properties and fields. The property or field should be serialized as XML text.
xref:System.Xml.Serialization.XmlTypeAttribute Public class declarations. The name and namespace of the XML type.

In addition to these attributes, which are all found in the xref:System.Xml.Serialization namespace, you can also apply the xref:System.ComponentModel.DefaultValueAttribute attribute to a field. The DefaultValueAttribute sets the value that will be automatically assigned to the member if no value is specified.

To control encoded SOAP XML serialization, see Attributes That Control Encoded SOAP Serialization.

See Also

XML and SOAP Serialization
xref:System.Xml.Serialization.XmlSerializer
Controlling XML Serialization Using Attributes
How to: Specify an Alternate Element Name for an XML Stream
How to: Serialize an Object
How to: Deserialize an Object