Class XmlGenerator
- Namespace
- SunamoXml.Generators
- Assembly
- SunamoXml.dll
Builds XML content using a StringBuilder. Supports tag writing, attributes, CDATA sections, and optional stack-based tracking of opened tags.
public class XmlGenerator
- Inheritance
-
XmlGenerator
- Derived
- Inherited Members
- Extension Methods
Constructors
XmlGenerator()
Initializes a new instance without stack tracking.
public XmlGenerator()
XmlGenerator(bool)
Initializes a new instance with optional stack tracking of opened tags.
public XmlGenerator(bool isUsingStack)
Parameters
isUsingStackboolWhether to track opened tags on a stack.
Properties
StringBuilder
The underlying StringBuilder that holds the generated XML content.
public StringBuilder StringBuilder { get; set; }
Property Value
Methods
AppendLine()
Appends a new line to the generated content.
public void AppendLine()
EndComment()
Writes an XML comment closing marker.
public void EndComment()
Insert(int, string)
Inserts text at the specified index in the generated content.
public void Insert(int index, string text)
Parameters
Length()
Returns the current length of the generated XML content.
public int Length()
Returns
StartComment()
Writes an XML comment opening marker.
public void StartComment()
TerminateTag(string)
Writes a closing tag for the specified element.
public void TerminateTag(string tagName)
Parameters
tagNamestringThe element name to close.
ToString()
Returns the generated XML content as a string.
public override string ToString()
Returns
WriteCData(string)
Writes a CDATA section with the specified content.
public void WriteCData(string innerCData)
Parameters
innerCDatastringThe content to wrap in CDATA.
WriteElement(string, string)
Writes a complete element with the specified inner content.
public void WriteElement(string elementName, string inner)
Parameters
WriteNonPairTag(string)
Writes a self-closing tag without attributes.
public void WriteNonPairTag(string tagName)
Parameters
tagNamestringThe element name.
WriteNonPairTagWith2Attrs(string, string, string, string, string)
Writes a self-closing tag with two attributes.
public void WriteNonPairTagWith2Attrs(string tagName, string firstName, string firstValue, string secondName, string secondValue)
Parameters
tagNamestringThe element name.
firstNamestringThe first attribute name.
firstValuestringThe first attribute value.
secondNamestringThe second attribute name.
secondValuestringThe second attribute value.
WriteNonPairTagWithAttr(string, string, string)
Writes a self-closing tag with one attribute.
public void WriteNonPairTagWithAttr(string tagName, string attrName, string attrValue)
Parameters
tagNamestringThe element name.
attrNamestringThe attribute name.
attrValuestringThe attribute value.
WriteNonPairTagWithAttrs(bool, string, params string[])
Writes a self-closing tag with multiple attributes, optionally including null values.
public void WriteNonPairTagWithAttrs(bool isAppendingNull, string tagName, params string[] attributes)
Parameters
isAppendingNullboolWhether to include attributes with null values.
tagNamestringThe element name.
attributesstring[]Alternating attribute names and values.
WriteNonPairTagWithAttrs(string, List<string>)
Writes a self-closing tag with multiple attributes from a list.
public void WriteNonPairTagWithAttrs(string tagName, List<string> attributes)
Parameters
tagNamestringThe element name.
attributesList<string>List of alternating attribute names and values.
WriteNonPairTagWithAttrs(string, params string[])
Writes a self-closing tag with multiple attributes.
public void WriteNonPairTagWithAttrs(string tagName, params string[] attributes)
Parameters
WriteRaw(string)
Writes raw content directly to the output.
public void WriteRaw(string rawContent)
Parameters
rawContentstringThe raw content to append.
WriteTag(string)
Writes an opening tag for the specified element.
public void WriteTag(string tagName)
Parameters
tagNamestringThe element name.
WriteTagNamespaceManager(string, XmlNamespaceManager, params string[])
Writes an opening tag with namespace manager declarations and additional attributes.
public void WriteTagNamespaceManager(string tagName, XmlNamespaceManager namespaceManager, params string[] attributes)
Parameters
tagNamestringThe element name.
namespaceManagerXmlNamespaceManagerThe namespace manager containing namespace declarations.
attributesstring[]Additional alternating attribute names and values.
WriteTagWith2Attrs(string, string, string, string, string)
Writes an opening tag with two attributes.
public void WriteTagWith2Attrs(string tagName, string firstName, string firstValue, string secondName, string secondValue)
Parameters
tagNamestringThe element name.
firstNamestringThe first attribute name.
firstValuestringThe first attribute value.
secondNamestringThe second attribute name.
secondValuestringThe second attribute value.
WriteTagWithAttr(string, string, string, bool)
Writes an opening tag with one attribute.
public void WriteTagWithAttr(string tagName, string attributeName, string attributeValue, bool isSkippingEmptyOrNull = false)
Parameters
tagNamestringThe element name.
attributeNamestringThe attribute name.
attributeValuestringThe attribute value.
isSkippingEmptyOrNullboolWhether to skip writing if the attribute value is empty or null.
WriteTagWithAttrs(string, List<string>)
Writes an opening tag with multiple attributes from a list.
public void WriteTagWithAttrs(string tagName, List<string> attributes)
Parameters
tagNamestringThe element name.
attributesList<string>List of alternating attribute names and values.
WriteTagWithAttrs(string, params string[])
Writes an opening tag with multiple attributes, skipping null values.
public void WriteTagWithAttrs(string tagName, params string[] attributes)
Parameters
WriteTagWithAttrsCheckNull(string, params string[])
Writes an opening tag with multiple attributes, skipping those with null values.
public void WriteTagWithAttrsCheckNull(string tagName, params string[] attributes)
Parameters
WriteXmlDeclaration()
Writes the standard XML declaration to the output.
public void WriteXmlDeclaration()