Class XmlStorage
Provides easy serialization to XML files.
Namespace: NanoByte.Common.Storage
Assembly: NanoByte.Common.dll
Syntax
public static class XmlStorage : Object
Fields
XsiNamespace
The XML namespace used for XML Schema instance.
Declaration
public const string XsiNamespace = "http://www.w3.org/2001/XMLSchema-instance"
Field Value
Type | Description |
---|---|
String |
Methods
FromXmlString<T>(String)
Loads an object from an XML string.
Declaration
public static T FromXmlString<T>(string data)
Parameters
Type | Name | Description |
---|---|---|
String | data | The XML string to be parsed. |
Returns
Type | Description |
---|---|
T | The loaded object. |
Type Parameters
Name | Description |
---|---|
T | The type of object the XML string shall be converted into. |
Exceptions
Type | Condition |
---|---|
InvalidDataException | A problem occurred while deserializing the XML data. |
LoadXml<T>(Stream)
Loads an object from an XML file.
Declaration
public static T LoadXml<T>(Stream stream)
Parameters
Type | Name | Description |
---|---|---|
Stream | stream | The stream to read the encoded XML data from. |
Returns
Type | Description |
---|---|
T | The loaded object. |
Type Parameters
Name | Description |
---|---|
T | The type of object the XML stream shall be converted into. |
Exceptions
Type | Condition |
---|---|
InvalidDataException | A problem occurred while deserializing the XML data. |
LoadXml<T>(String)
Loads an object from an XML file.
Declaration
public static T LoadXml<T>(string path)
Parameters
Type | Name | Description |
---|---|---|
String | path | The path of the file to load. |
Returns
Type | Description |
---|---|
T | The loaded object. |
Type Parameters
Name | Description |
---|---|
T | The type of object the XML stream shall be converted into. |
Remarks
Uses AtomicRead internally.
Exceptions
Type | Condition |
---|---|
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.
Declaration
public static void SaveXml(this object data, Stream stream, string stylesheet = null)
Parameters
Type | Name | Description |
---|---|---|
Object | data | The object to be stored. |
Stream | stream | The stream to write the encoded XML data to. |
String | stylesheet | The path of an XSL stylesheet; can be |
SaveXml<T>(T, String, String)
Saves an object in an XML file ending with a line break.
Declaration
public static void SaveXml<T>(this T data, string path, string stylesheet = null)
Parameters
Type | Name | Description |
---|---|---|
T | data | The object to be stored. |
String | path | The path of the file to write. |
String | stylesheet | The path of an XSL stylesheet for |
Type Parameters
Name | Description |
---|---|
T | The type of object to be saved in an XML stream. |
Remarks
This method performs an atomic write operation when possible.
Exceptions
Type | Condition |
---|---|
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.
Declaration
public static string ToXmlString(this object data, string stylesheet = null)
Parameters
Type | Name | Description |
---|---|---|
Object | data | The object to be stored. |
String | stylesheet | The path of an XSL stylesheet; can be |
Returns
Type | Description |
---|---|
String | A string containing the XML code. |