System.Xml.Serialization.IXmlSerializable Interface

Assembly: System.Xml.dll
Namespace: System.Xml.Serialization
This type supports the Shared Source CLI infrastructure and is not intended to be used directly from your code.
Summary
Provides a custom serialization format for a serializable object.
C# Syntax:
public interface IXmlSerializable
Remarks
Examples of classes that implement this interface are DataSet and XmlDocument. This is different from the ISerializable interface in that it is totally XML-centric and stream based in the sense that large amounts of XML can be incrementally streamed through the DataSet.ReadXml and DataSet.WriteXml methods.
See also:
System.Xml.Serialization Namespace

System.Xml.Serialization.IXmlSerializable Member List:

Public Methods
GetSchema
ReadXml Converts an XML document into an object using the specified reader.
WriteXml Converts the serializable members of an object into an XML document.

System.Xml.Serialization.IXmlSerializable Member Details

Method: GetSchema()
C# Syntax:
XmlSchema GetSchema();
Return Value:
An XmlSchema object that represents the XML schema.
Remarks
This optional method is used by webserviceutil to create a callable web service client class from the returned XmlSchema object. This method is not needed to do simple runtime XML serialization.

Return to top


Method: ReadXml(
   XmlReader reader
)
Summary
Converts an XML document into an object using the specified reader.
C# Syntax:
void ReadXml(
   XmlReader reader
);
Parameters:

reader

The XmlReader used to read the XML document.

Remarks
The reader is positioned within the stream at the point that you began writing (in IXmlSerializable.WriteXml). It is your responsibility to read everything you wrote, no less and no more.

Return to top


Method: WriteXml(
   XmlWriter writer
)
Summary
Converts the serializable members of an object into an XML document.
C# Syntax:
void WriteXml(
   XmlWriter writer
);
Parameters:

writer

The XmlWriter used to write the XML-document instance.

Remarks
You must write enough information to be able to implement the IXmlSerializable.ReadXml method correctly. For example, if you are writing a list of elements, you provide a way to know how many you wrote so that IXmlSerializable.ReadXml knows how when to stop reading. There are three ways to do this:

Method Example
Write an initial count in the XML-instance document. <count>5</count> <item> ... </item>
Write an end marker in the XML-instance document. <item> ...</item> <endItems/>
Write a single container. <items> <item>... </item> <item> ... </item> </items>

To test, you should serialize two instances of the object back-to-back, then deserialize both instances.

Return to top


Top of page

Copyright (c) 2002 Microsoft Corporation. All rights reserved.