using System.Xml; namespace SabreTools.Library.IO { /// /// Additional methods for XmlTextWriter /// public static class XmlTextWriterExtensions { // TODO: Rename Full to Required, add one for attributes /// /// 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 ?? string.Empty); writer.WriteFullEndElement(); } /// /// 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 WriteOptionalAttributeString(this XmlTextWriter writer, string localName, string value) { if (string.IsNullOrEmpty(value)) writer.WriteAttributeString(localName, value); } /// /// Write an element, if the value is not null or empty /// /// XmlTextWriter to write out with /// Name of the element /// Value to write in the element public static void WriteOptionalElementString(this XmlTextWriter writer, string localName, string value) { if (string.IsNullOrEmpty(value)) writer.WriteElementString(localName, value); } } }