Table of Contents

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

isUsingStack bool

Whether 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

StringBuilder

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

index int

The position to insert at.

text string

The text to insert.

Length()

Returns the current length of the generated XML content.

public int Length()

Returns

int

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

tagName string

The element name to close.

ToString()

Returns the generated XML content as a string.

public override string ToString()

Returns

string

WriteCData(string)

Writes a CDATA section with the specified content.

public void WriteCData(string innerCData)

Parameters

innerCData string

The 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

elementName string

The element name.

inner string

The inner content of the element.

WriteNonPairTag(string)

Writes a self-closing tag without attributes.

public void WriteNonPairTag(string tagName)

Parameters

tagName string

The 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

tagName string

The element name.

firstName string

The first attribute name.

firstValue string

The first attribute value.

secondName string

The second attribute name.

secondValue string

The 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

tagName string

The element name.

attrName string

The attribute name.

attrValue string

The 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

isAppendingNull bool

Whether to include attributes with null values.

tagName string

The element name.

attributes string[]

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

tagName string

The element name.

attributes List<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

tagName string

The element name.

attributes string[]

Alternating attribute names and values.

WriteRaw(string)

Writes raw content directly to the output.

public void WriteRaw(string rawContent)

Parameters

rawContent string

The raw content to append.

WriteTag(string)

Writes an opening tag for the specified element.

public void WriteTag(string tagName)

Parameters

tagName string

The 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

tagName string

The element name.

namespaceManager XmlNamespaceManager

The namespace manager containing namespace declarations.

attributes string[]

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

tagName string

The element name.

firstName string

The first attribute name.

firstValue string

The first attribute value.

secondName string

The second attribute name.

secondValue string

The 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

tagName string

The element name.

attributeName string

The attribute name.

attributeValue string

The attribute value.

isSkippingEmptyOrNull bool

Whether 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

tagName string

The element name.

attributes List<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

tagName string

The element name.

attributes string[]

Alternating attribute names and values.

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

tagName string

The element name.

attributes string[]

Alternating attribute names and values.

WriteXmlDeclaration()

Writes the standard XML declaration to the output.

public void WriteXmlDeclaration()