2022-02-09 18:49:52 +00:00
|
|
|
namespace ASC.Data.Backup.Extensions;
|
|
|
|
|
|
|
|
public static class XmlExtensions
|
2020-05-20 15:14:44 +00:00
|
|
|
{
|
2022-02-09 18:49:52 +00:00
|
|
|
public static string ValueOrDefault(this XElement el)
|
2020-05-20 15:14:44 +00:00
|
|
|
{
|
2022-02-09 18:49:52 +00:00
|
|
|
return el?.Value;
|
|
|
|
}
|
2020-05-20 15:14:44 +00:00
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
public static string ValueOrDefault(this XAttribute attr)
|
|
|
|
{
|
|
|
|
return attr?.Value;
|
|
|
|
}
|
2020-05-20 15:14:44 +00:00
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
public static void WriteTo(this XElement el, Stream stream)
|
|
|
|
{
|
|
|
|
WriteTo(el, stream, Encoding.UTF8);
|
|
|
|
}
|
2020-05-20 15:14:44 +00:00
|
|
|
|
2022-02-09 18:49:52 +00:00
|
|
|
public static void WriteTo(this XElement el, Stream stream, Encoding encoding)
|
|
|
|
{
|
|
|
|
var data = encoding.GetBytes(el.ToString(SaveOptions.None));
|
|
|
|
stream.Write(data, 0, data.Length);
|
2020-05-20 15:14:44 +00:00
|
|
|
}
|
|
|
|
}
|