Class
ReportXmlSerializer

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:

cs-api-definition
public class ReportXmlSerializer

Inheritance: objectReportXmlSerializer

Constructors

ReportXmlSerializer()

Initializes a new instance of the ReportXmlSerializer class.

Declaration

cs-api-definition
public ReportXmlSerializer()

Methods

Deserialize(Stream)

Deserializes the XML document contained by the specified Stream.

Declaration

cs-api-definition
public object Deserialize(Stream stream)

Parameters

stream

Stream

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 

Deserialize(TextReader)

Deserializes the XML document contained by the specified TextReader.

Declaration

cs-api-definition
public object Deserialize(TextReader reader)

Parameters

reader

TextReader

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 

Deserialize(XmlReader)

Deserializes the XML document contained by the specified XmlReader.

Declaration

cs-api-definition
public object Deserialize(XmlReader reader)

Parameters

reader

XmlReader

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 

Deserialize(string)

Deserializes the XML document from the specified URI.

Declaration

cs-api-definition
public object Deserialize(string inputUri)

Parameters

inputUri

string

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) 

Serialize(Stream, object)

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

Declaration

cs-api-definition
public void Serialize(Stream stream, object value)

Parameters

stream

Stream

The Stream used to write the XML document.

value

object

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 

Serialize(TextWriter, object)

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

Declaration

cs-api-definition
public void Serialize(TextWriter writer, object value)

Parameters

writer

TextWriter

The TextWriter used to write the XML document.

value

object

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 

Serialize(XmlWriter, object)

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

Declaration

cs-api-definition
public void Serialize(XmlWriter writer, object value)

Parameters

writer

XmlWriter

The XmlWriter used to write the XML document.

value

object

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 

Serialize(string, object)

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

Declaration

cs-api-definition
public void Serialize(string fileName, object value)

Parameters

fileName

string

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.

value

object

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)