Skip to content

Element

Adds a new element with the specified name and value.

1
myXmlWriter.Element(name: string, value: ( string | number | boolean | DateTimeOffset )):XmlWriter

Parameters

string name
    Name of the element to add.

( string | number | boolean | DateTimeOffset ) value
    Value of the element. This value will be XML encoded.

Returns

The current XmlWriter instance, allowing for method chaining.

Remarks

This method creates a new element with the specified name and value as a child of the current element.
The value is encoded using XML encoding rules to ensure proper formatting and prevent potential security issues.

Example

1
2
3
4
var writer = $Xml.Create();
writer.Element('Customer', 'Doe');
var xml = writer.ToXml();
// xml: <Customer>Doe</Customer>

See Also