Skip to content

StartElement

Starts a new element with the specified name.

1
myXmlWriter.StartElement(name: string):XmlWriter

Starts a new element with the specified name and namespace.

1
myXmlWriter.StartElement(name: string, ns: string):XmlWriter

Parameters

string name
    The name of the element to start.

string ns
    The namespace URI of the element.

Returns

The current XmlWriter instance, allowing for method chaining.

Remarks

This method creates a new element and makes it the current element for subsequent operations. Close every started element with XmlWriter.EndElement.

Examples

Write nested elements

1
2
3
4
5
6
7
8
9
var writer = $Xml.Create();
writer.StartElement('Customer')
    .Element('Name', 'Jane Doe')
    .StartElement('Address')
    .Element('City', 'Springfield')
    .EndElement()
    .EndElement();
var xml = writer.ToXml();
// '<Customer><Name>Jane Doe</Name><Address><City>Springfield</City></Address></Customer>'

Write an element in a namespace

1
2
3
4
5
var writer = $Xml.Create();
writer.StartElement('Customer', 'urn:example:crm')
    .Element('Name', 'Jane Doe')
    .EndElement();
var xml = writer.ToXml();

See Also