using System.Xml;
namespace SabreTools.Library.IO
{
///
/// Additional methods for XmlTextWriter
///
public static class XmlTextWriterExtensions
{
///
/// Write an attribute, if the value is not null or empty
///
/// XmlTextWriter to write out with
/// Name of the attribute
/// Value to write in the attribute
public static void WriteAttributeStringIfExists(this XmlTextWriter writer, string localName, string value)
{
if (string.IsNullOrEmpty(value))
writer.WriteAttributeString(localName, value);
}
///
/// Force writing separate open and start tags, even for empty elements
///
/// XmlTextWriter to write out with
/// Name of the element
/// Value to write in the element
public static void WriteFullElementString(this XmlTextWriter writer, string localName, string value)
{
writer.WriteStartElement(localName);
writer.WriteRaw(value);
writer.WriteFullEndElement();
}
}
}