Table of Contents

Class XmlStorage

Namespace
NanoByte.Common.Storage
Assembly
NanoByte.Common.dll

Provides easy serialization to XML files.

public static class XmlStorage
Inheritance
XmlStorage

Fields

XsiNamespace

The XML namespace used for XML Schema instance.

public const string XsiNamespace = "http://www.w3.org/2001/XMLSchema-instance"

Field Value

string

Methods

FromXmlString<T>(string)

Loads an object from an XML string.

public static T FromXmlString<T>(string data)

Parameters

data string

The XML string to be parsed.

Returns

T

The loaded object.

Type Parameters

T

The type of object the XML string shall be converted into.

Exceptions

InvalidDataException

A problem occurred while deserializing the XML data.

LoadXml<T>(Stream)

Loads an object from an XML file.

public static T LoadXml<T>(Stream stream)

Parameters

stream Stream

The stream to read the encoded XML data from.

Returns

T

The loaded object.

Type Parameters

T

The type of object the XML stream shall be converted into.

Exceptions

InvalidDataException

A problem occurred while deserializing the XML data.

LoadXml<T>(string)

Loads an object from an XML file.

public static T LoadXml<T>(string path)

Parameters

path string

The path of the file to load.

Returns

T

The loaded object.

Type Parameters

T

The type of object the XML stream shall be converted into.

Remarks

Uses AtomicRead internally.

Exceptions

IOException

A problem occurred while reading the file.

UnauthorizedAccessException

Read access to the file is not permitted.

InvalidDataException

A problem occurred while deserializing the XML data.

SaveXml(object, Stream, string?)

Saves an object in an XML stream ending with a line break.

public static void SaveXml(this object data, Stream stream, string? stylesheet = null)

Parameters

data object

The object to be stored.

stream Stream

The stream to write the encoded XML data to.

stylesheet string

The path of an XSL stylesheet; can be null.

SaveXml<T>(T, string, string?)

Saves an object in an XML file ending with a line break.

public static void SaveXml<T>(this T data, string path, string? stylesheet = null) where T : notnull

Parameters

data T

The object to be stored.

path string

The path of the file to write.

stylesheet string

The path of an XSL stylesheet for T; can be null.

Type Parameters

T

The type of object to be saved in an XML stream.

Remarks

This method performs an atomic write operation when possible.

Exceptions

IOException

A problem occurred while writing the file.

UnauthorizedAccessException

Write access to the file is not permitted.

ToXmlString(object, string?)

Returns an object as an XML string ending with a line break.

public static string ToXmlString(this object data, string? stylesheet = null)

Parameters

data object

The object to be stored.

stylesheet string

The path of an XSL stylesheet; can be null.

Returns

string

A string containing the XML code.