Export (0) Print
Expand All

IXmlSerializable.ReadXml Method

Generates an object from its XML representation.

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

'Declaration
Sub ReadXml ( _
	reader As XmlReader _
)
'Usage
Dim instance As IXmlSerializable
Dim reader As XmlReader

instance.ReadXml(reader)
void ReadXml (
	XmlReader reader
)
function ReadXml (
	reader : XmlReader
)
Not applicable.

Parameters

reader

The XmlReader stream from which the object is deserialized.

The ReadXml method must reconstitute your object using the information that was written by the WriteXml method.

When this method is called, the reader is positioned at the start of the element that wraps the information for your type. That is, just before the start tag that indicates the beginning of a serialized object. When this method returns, it must have read the entire element from beginning to end, including all of its contents. Unlike the WriteXml method, the framework does not handle the wrapper element automatically. Your implementation must do so. Failing to observe these positioning rules may cause code to generate unexpected runtime exceptions or corrupt data.

When implementing this method, you should consider the possibility that a malicious user might provide a well-formed but invalid XML representation in order to disable or otherwise alter the behavior of your application.

The following example illustrates an implementation of the ReadXml method.

No code example is currently available or this language may not be supported.
public void ReadXml(XmlReader reader)
{
    personName = reader.ReadString();
} //ReadXml


The following example illustrates the use of the XmlSerializer class to deserialize this object.

No code example is currently available or this language may not be supported.
import System.*;
import System.IO.*;
import System.Xml.Serialization.*;
import System.Xml.Schema.* ;
import System.Xml.XmlWriter;
import System.Xml.XmlReader;

public class Reader
{
    public static void main(String[] args)
    {
        XmlSerializer serializer = new XmlSerializer(Person.class.ToType());
        FileStream file = new FileStream("test.xml", FileMode.Open);
        Person aPerson = (Person)(serializer.Deserialize(file));
        Console.WriteLine(aPerson);
    } //main
} //Reader 

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2014 Microsoft