Partager via


System.Xml.Serialization Namespace

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

The System.Xml.Serialization namespace contains classes that are used to serialize objects into XML-format documents or streams.

The central class in the namespace is the XmlSerializer class. To use this class, use the XmlSerializer constructor to create an instance of the class using the type of the object to serialize. After an XmlSerializer is created, create an instance of the object to serialize. You must also create an object to write the file to a document or stream, such as a Stream, TextWriter, or XmlWriter. You can then call the Serialize() method to convert the object into an XML document.

To deserialize an object from an XML document, create a suitable object to read the document or stream (again, a Stream, TextWriter, or XmlWriter). Invoke the Deserialize() method while casting the resulting object to the type of the original object (that was serialized).

To further control the serialization, the System.Xml.Serialization namespace contains several Attribute classes that can be applied to members of a class. For example, if a class contains a member that will be serialized as an XML element, you can apply the XmlElementAttribute attribute to the member. When applying the attribute, you can specify details such as the actual XML element name using the ElementName property. For a complete list of all the attributes, see the XmlSerializer class overview.

Classes

  Class Description
Public class XmlAnyElementAttribute Specifies that the member (a field that returns an array of XElement or XNode objects) contains objects that represent an XML element that has no corresponding member in the object being serialized or deserialized.
Public class XmlAnyElementAttributes Represents a collection of XmlAnyElementAttribute objects.
Public class XmlArrayAttribute Specifies that the XmlSerializer must serialize a particular class member as an array of XML elements.
Public class XmlArrayItemAttribute Specifies the derived types that the XmlSerializer can place in a serialized array.
Public class XmlArrayItemAttributes Represents a collection of XmlArrayItemAttribute objects.
Public class XmlAttributeAttribute Specifies that the XmlSerializer must serialize the class member as an XML attribute.
Public class XmlAttributeOverrides Allows you to override property, field, and class attributes when you use the XmlSerializer to serialize or deserialize an object.
Public class XmlAttributes Represents a collection of attribute objects that control how the XmlSerializer serializes and deserializes an object.
Public class XmlChoiceIdentifierAttribute Specifies that the member can be further detected by using an enumeration.
Public class XmlElementAttribute Indicates that a public field or property represents an XML element when the XmlSerializer serializes or deserializes the object that contains it.
Public class XmlElementAttributes Represents a collection of XmlElementAttribute objects used by the XmlSerializer to override the default way it serializes a class.
Public class XmlEnumAttribute Controls how the XmlSerializer serializes an enumeration member.
Public class XmlIgnoreAttribute Instructs the Serialize method of the XmlSerializer class not to serialize the public field or public read/write property value.
Public class XmlIncludeAttribute Allows the XmlSerializer to recognize a type when it serializes or deserializes an object.
Public class XmlMapping Infrastructure. Supports mappings between .NET Framework types and XML Schema data types.
Public class XmlMemberMapping Infrastructure. Maps a code entity in a .NET Framework Web service method to an element in a Web Services Description Language (WSDL) message.
Public class XmlMembersMapping Infrastructure. Provides mappings between .NET Framework Web service methods and Web Services Description Language (WSDL) messages that are defined for SOAP Web services.
Public class XmlNamespaceDeclarationsAttribute Specifies that the target property, parameter, return value, or class member contains prefixes associated with namespaces that are used within an XML document.
Public class XmlReflectionImporter Infrastructure. Generates mappings to XML schema element declarations, including literal XML Schema Definition (XSD) message parts in a Web Services Description Language (WSDL) document for .NET Framework types or Web service method information.
Public class XmlReflectionMember Infrastructure. Provides mappings between code entities in .NET Framework Web service methods and the content of Web Services Description Language (WSDL) messages that are defined for SOAP Web services.
Public class XmlRootAttribute Controls XML serialization of the attribute target as an XML root element.
Public class XmlSchemaProviderAttribute When applied to a type that implements the IXmlSerializable interface, stores the name of a static method of the type that returns an XML schema and a XmlQualifiedName (or XmlSchemaType for anonymous types) that controls the serialization of the type.
Public class XmlSerializationGeneratedCode Infrastructure. An abstract class that is the base class for XmlSerializationReader and XmlSerializationWriter and that contains methods common to both of these types.
Public class XmlSerializationReader Infrastructure. Controls deserialization by the XmlSerializer class.
Public class XmlSerializationWriter Infrastructure. Abstract class used for controlling serialization by the XmlSerializer class.
Public class XmlSerializer Serializes and deserializes objects into and from XML documents. The XmlSerializer enables you to control how objects are encoded into XML.
Public class XmlSerializerImplementation Infrastructure. Defines the reader, writer, and methods for pre-generated, typed serializers.
Public class XmlSerializerNamespaces Contains the XML namespaces and prefixes that the XmlSerializer uses to generate qualified names in an XML-document instance.
Public class XmlTextAttribute Indicates to the XmlSerializer that the member must be treated as XML text when the class that contains it is serialized or deserialized.
Public class XmlTypeAttribute Controls the XML schema that is generated when the attribute target is serialized by the XmlSerializer.
Public class XmlTypeMapping Contains a mapping of one type to another.

Interfaces

  Interface Description
Public interface IXmlSerializable Provides custom formatting for XML serialization and deserialization to control how your object is serialized or deserialized by the XmlSerializer.

Delegates

  Delegate Description
Public delegate XmlSerializationWriteCallback Delegate supporting the .NET Framework infrastructure that is used by the XmlSerializer class for serialization of types from SOAP-encoded, non-root XML data.

Enumerations

  Enumeration Description
Public enumeration XmlMappingAccess Infrastructure. Specifies whether a mapping is read, write, or both.