Class XmlStorage
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
Methods
FromXmlString<T>(string)
Loads an object from an XML string.
public static T FromXmlString<T>(string data)
Parameters
data
stringThe 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
StreamThe 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
stringThe 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
objectThe object to be stored.
stream
StreamThe stream to write the encoded XML data to.
stylesheet
stringThe 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
TThe object to be stored.
path
stringThe path of the file to write.
stylesheet
stringThe path of an XSL stylesheet for
T
; can benull
.
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
Returns
- string
A string containing the XML code.