Table of Contents

Class XmlStorage

Namespace
OmegaEngine.Foundation.Storage
Assembly
OmegaEngine.Foundation.dll

Provides easy serialization to XML files (optionally wrapped in ZIP archives).

public static class XmlStorage
Inheritance
XmlStorage
Inherited Members

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) where T : class

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.

LoadXmlZip<T>(Stream, string?, params EmbeddedFile[])

Loads an object from an XML file embedded in a ZIP archive.

public static T LoadXmlZip<T>(Stream stream, string? password = null, params EmbeddedFile[] additionalFiles) where T : class

Parameters

stream Stream

The ZIP archive to load.

password string

The password to use for decryption; null for no encryption.

additionalFiles EmbeddedFile[]

Additional files stored alongside the XML file in the ZIP archive to be read.

Returns

T

The loaded object.

Type Parameters

T

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

Exceptions

ZipException

A problem occurred while reading the ZIP data or if password is wrong.

InvalidDataException

A problem occurred while deserializing the XML data.

LoadXmlZip<T>(string, string?, params EmbeddedFile[])

Loads an object from an XML file embedded in a ZIP archive.

public static T LoadXmlZip<T>(string path, string? password = null, params EmbeddedFile[] additionalFiles) where T : class

Parameters

path string

The ZIP archive to load.

password string

The password to use for decryption; null for no encryption.

additionalFiles EmbeddedFile[]

Additional files stored alongside the XML file in the ZIP archive to be read.

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.

ZipException

A problem occurred while reading the ZIP data or if password is wrong.

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) where T : class

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) where T : class

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.

SaveXmlZip<T>(T, Stream, string?, params EmbeddedFile[])

Saves an object in an XML file embedded in a ZIP archive.

public static void SaveXmlZip<T>(this T data, Stream stream, string? password = null, params EmbeddedFile[] additionalFiles)

Parameters

data T

The object to be stored.

stream Stream

The ZIP archive to be written.

password string

The password to use for encryption; null for no encryption.

additionalFiles EmbeddedFile[]

Additional files to be stored alongside the XML file in the ZIP archive; can be null.

Type Parameters

T

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

SaveXmlZip<T>(T, string, string?, params EmbeddedFile[])

Saves an object in an XML file embedded in a ZIP archive.

public static void SaveXmlZip<T>(this T data, string path, string? password = null, params EmbeddedFile[] additionalFiles)

Parameters

data T

The object to be stored.

path string

The ZIP archive to be written.

password string

The password to use for encryption; null for no encryption.

additionalFiles EmbeddedFile[]

Additional files to be stored alongside the XML file in the ZIP archive; can be null.

Type Parameters

T

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

Remarks

Uses AtomicWrite internally.

Exceptions

IOException

A problem occurred while writing the file.

UnauthorizedAccessException

Write access to the file is not permitted.

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

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

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

Parameters

data T

The object to be stored.

stream Stream

The stream to write the encoded XML data to.

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.

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)

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<T>(T, string?)

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

public static string ToXmlString<T>(this T data, string? stylesheet = null)

Parameters

data T

The object to be stored.

stylesheet string

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

Returns

string

A string containing the XML code.

Type Parameters

T

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