2020-08-23 21:10:29 -07:00
|
|
|
|
using System.Xml;
|
|
|
|
|
|
|
|
|
|
|
|
namespace SabreTools.Library.IO
|
|
|
|
|
|
{
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Additional methods for XmlTextWriter
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
public static class XmlTextWriterExtensions
|
|
|
|
|
|
{
|
2020-08-23 22:23:55 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Write an attribute, if the value is not null or empty
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="writer">XmlTextWriter to write out with</param>
|
|
|
|
|
|
/// <param name="localName">Name of the attribute</param>
|
|
|
|
|
|
/// <param name="value">Value to write in the attribute</param>
|
2020-08-23 22:54:09 -07:00
|
|
|
|
public static void WriteOptionalAttributeString(this XmlTextWriter writer, string localName, string value)
|
2020-08-23 22:23:55 -07:00
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(value))
|
|
|
|
|
|
writer.WriteAttributeString(localName, value);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-08-23 21:10:29 -07:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Force writing separate open and start tags, even for empty elements
|
|
|
|
|
|
/// </summary>
|
2020-08-23 22:23:55 -07:00
|
|
|
|
/// <param name="writer">XmlTextWriter to write out with</param>
|
2020-08-23 21:10:29 -07:00
|
|
|
|
/// <param name="localName">Name of the element</param>
|
|
|
|
|
|
/// <param name="value">Value to write in the element</param>
|
2020-08-23 22:23:55 -07:00
|
|
|
|
public static void WriteFullElementString(this XmlTextWriter writer, string localName, string value)
|
2020-08-23 21:10:29 -07:00
|
|
|
|
{
|
2020-08-23 22:23:55 -07:00
|
|
|
|
writer.WriteStartElement(localName);
|
|
|
|
|
|
writer.WriteRaw(value);
|
|
|
|
|
|
writer.WriteFullEndElement();
|
2020-08-23 21:10:29 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|