System.Xml.Serialization.XmlSerializer.Serialize Method

Serializes the specified object and writes the XML document to a file using the specified System.Xml.XmlWriter and references the specified namespaces and encoding style.

Syntax

public void Serialize (System.Xml.XmlWriter xmlWriter, object o, XmlSerializerNamespaces namespaces, string encodingStyle)

Parameters

xmlWriter
The System.xml.XmlWriter used to write the XML document.
o
The object to serialize.
namespaces
The System.Xml.Serialization.XmlSerializerNamespaces referenced by the object.
encodingStyle
The encoding style of the serialized XML.

Remarks

When the XmlSerializer.Serialize(System.IO.TextWriter, object) method is invoked, the public fields and read/write properties of an object are converted into XML. Methods, indexers, private fields, and read-only properties are not serialized. To serialize all fields and properties, both public and private, use the System.Runtime.Serialization.Formatters.Binary.BinaryFormatter.

Use the xmlWriter parameter to specify an object that derives from the abstract System.Xml.XmlWriter class, which is designed to write XML documents. The System.Xml.XmlTextWriter derives from the System.Xml.XmlWriter.

Set the encodingStyle parameter to "http://schemas.xmlsoap.org/soap/encoding/" for SOAP version 1.1 encoding; otherwise, set it to "http://www.w3.org/2001/12/soap-encoding" for SOAP version 1.2 encoding.

Note:

The System.Xml.Serialization.XmlSerializer cannot serialize the following: arrays of ArrayList and arrays of List`1.

Requirements

Namespace: System.Xml.Serialization
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0