Skip to content

Attribute

Adds a new attribute with the specified name and value to the current element.

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

Parameters

string name
    Name of the attribute to add.

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

Returns

The current XmlWriter instance, allowing for method chaining.

Remarks

This method adds a new attribute with the specified name and value to 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
5
6
var writer = $Xml.Create();
writer.StartElement('Customer');
writer.Attribute('Name', 'Doe');
writer.EndElement();
var xml = writer.ToXml();
// xml: <Customer Name="Doe" />

See Also