New to Telerik Reporting? Start a free 30-day trial

Serializes and deserializes objects into and from XML. This class is dedicated for serializing and deserializing objects only from the Telerik.Reporting namespace.

Definition

Namespace:Telerik.Reporting.XmlSerialization

Assembly:Telerik.Reporting.dll

Syntax:

C#
public class ReportXmlSerializer

Inheritance: objectReportXmlSerializer

Constructors

Initializes a new instance of the ReportXmlSerializer class.

C#
public ReportXmlSerializer()

Methods

Deserializes the XML document contained by the specified Stream.

C#
public object Deserialize(Stream stream)
Parameters:streamStream

The Stream that contains the XML document to deserialize.

Returns:

object

The Telerik.Reporting object being deserialized.

Remarks:

Use the stream parameter to specify an object that derives from the Stream class, which is designed to write to streams. Classes that derive from the Stream class include: BufferedStream, FileStream, MemoryStream, etc.

Example:

The following example deserializes an object using a Stream:

cs
using (System.IO.FileStream fileStream = new System.IO.FileStream("Report1.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read))
{
    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
        new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

    Telerik.Reporting.Report report = (Telerik.Reporting.Report)
        xmlSerializer.Deserialize(fileStream);
}
vb
Using fileStream As New System.IO.FileStream("Report1.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read)
    Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()

    Dim report As Telerik.Reporting.Report = DirectCast(xmlSerializer.Deserialize(fileStream), Telerik.Reporting.Report)
End Using 

Deserializes the XML document from the specified URI.

C#
public object Deserialize(string inputUri)
Parameters:inputUristring

The URI for the file containing the XML data.

Returns:

object

The Telerik.Reporting object being deserialized.

Example:

The following example deserializes an object using a URI:

cs
Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
    new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

Telerik.Reporting.Report report = (Telerik.Reporting.Report)
    xmlSerializer.Deserialize("Report1.xml");
vb
Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()
Dim report As Telerik.Reporting.Report = DirectCast(xmlSerializer.Deserialize("Report1.xml"), Telerik.Reporting.Report) 

Deserializes the XML document contained by the specified TextReader.

C#
public object Deserialize(TextReader reader)
Parameters:readerTextReader

The TextReader that contains the XML document to deserialize.

Returns:

object

The Telerik.Reporting object being deserialized.

Remarks:

Classes that inherit from TextReader include StringReader and StreamReader. If you are using a StreamReader to deserialize an object, you must construct the StreamReader with an appropriate Encoding. The encoding specified by the XML document is ignored.

Example:

The following example deserializes an object using a TextReader:

cs
using (System.IO.FileStream fileStream = new System.IO.FileStream("Report1.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read))
using (System.IO.TextReader textReader = new System.IO.StreamReader(fileStream))
{
    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
        new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

    Telerik.Reporting.Report report = (Telerik.Reporting.Report)
        xmlSerializer.Deserialize(textReader);
}
vb
Using fileStream As New System.IO.FileStream("Report1.xml", System.IO.FileMode.Open, System.IO.FileAccess.Read)
    Using textReader As System.IO.TextReader = New System.IO.StreamReader(fileStream)
        Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()

        Dim report As Telerik.Reporting.Report = DirectCast(xmlSerializer.Deserialize(textReader), Telerik.Reporting.Report)
    End Using
End Using 

Deserializes the XML document contained by the specified XmlReader.

C#
public object Deserialize(XmlReader reader)
Parameters:readerXmlReader

The XmlReader that contains the XML document to deserialize.

Returns:

object

The Telerik.Reporting object being deserialized.

Example:

The following example deserializes an object using a XmlReader:

cs
System.Xml.XmlReaderSettings settings = new System.Xml.XmlReaderSettings();
settings.IgnoreWhitespace = true;

using (System.Xml.XmlReader xmlReader = System.Xml.XmlReader.Create("Report1.xml", settings))
{
    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
        new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

    Telerik.Reporting.Report report = (Telerik.Reporting.Report)
        xmlSerializer.Deserialize(xmlReader);
}
vb
Dim settings As New XmlReaderSettings() settings.IgnoreWhitespace = True
Using xmlReader As System.Xml.XmlReader = System.Xml.XmlReader.Create("Report1.xml", settings)
    Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()

    Dim report As Telerik.Reporting.Report = DirectCast(xmlSerializer.Deserialize(xmlReader), Telerik.Reporting.Report)
End Using 

Serializes the specified value and writes the XML document to the specified Stream.

C#
public void Serialize(Stream stream, object value)
Parameters:streamStream

The Stream used to write the XML document.

valueobject

The value to serialize.

Remarks:

Use the stream parameter to specify an object that derives from the abstract Stream class. Classes that derive from the Stream class include: BufferedStream, FileStream, MemoryStream, etc.

Example:

The following examples serializes an object using a Stream:

cs
using (System.IO.Stream stream = new System.IO.FileStream("Report.xml", System.IO.FileMode.Create))
{
    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
        new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

    xmlSerializer.Serialize(stream, report);
}
vb
Using stream As System.IO.Stream = New System.IO.FileStream("Report.xml", System.IO.FileMode.Create)
    Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()

    xmlSerializer.Serialize(stream, report)
End Using 

Serializes the specified value and writes the XML document to a file with the specified file name.

C#
public void Serialize(string fileName, object value)
Parameters:fileNamestring

The file which you want to write to. The ReportXmlSerializer creates a file at the specified path and writes to it in XML 1.0 text syntax. The fileName must be a file system path.

valueobject

The value to serialize.

Example:

The following example serializes an object using a file path:

cs
Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
    new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

xmlSerializer.Serialize("Report.xml", report);
vb
Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()
xmlSerializer.Serialize("Report.xml", report) 

Serializes the specified value and writes the XML document to the specified TextWriter.

C#
public void Serialize(TextWriter writer, object value)
Parameters:writerTextWriter

The TextWriter used to write the XML document.

valueobject

The value to serialize.

Remarks:

In the textWriter parameter, specify an object that derives from the abstract TextWriter class. Classes that derive from the TextWriter class include: StreamWriter, StringWriter, etc.

Example:

The following examples serializes an object using a TextWriter:

cs
using (System.IO.FileStream fs = new System.IO.FileStream("Report.xml", FileMode.Create))
using (System.IO.TextWriter writer = new System.IO.StreamWriter(fs, System.Text.Encoding.UTF8))
{
    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
        new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

    xmlSerializer.Serialize(writer, report);
}
vb
Using fs As New System.IO.FileStream("Report.xml", System.IO.FileMode.Create)
    Using writer As System.IO.TextWriter = New System.IO.StreamWriter(fs, System.Text.Encoding.UTF8)
        Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()

        xmlSerializer.Serialize(writer, report)
    End Using
End Using 

Serializes the specified value and writes the XML document to the specified XmlWriter.

C#
public void Serialize(XmlWriter writer, object value)
Parameters:writerXmlWriter

The XmlWriter used to write the XML document.

valueobject

The value to serialize.

Remarks:

In the xmlWriter parameter, specify an object that derives from the abstract XmlWriter class. For example you can use the XmlTextWriter class.

Example:

The following example serializes an object using a XmlWriter:

cs
using (System.Xml.XmlWriter xmlWriter = System.Xml.XmlWriter.Create("SerializedReport.xml"))
{
    Telerik.Reporting.XmlSerialization.ReportXmlSerializer xmlSerializer =
        new Telerik.Reporting.XmlSerialization.ReportXmlSerializer();

    xmlSerializer.Serialize(xmlWriter, report);
}
vb
Using xmlWriter As System.Xml.XmlWriter = System.Xml.XmlWriter.Create("SerializedReport.xml")
    Dim xmlSerializer As New Telerik.Reporting.XmlSerialization.ReportXmlSerializer()

    xmlSerializer.Serialize(xmlWriter, report)
End Using