Skip to content

Xml

Writes the given XML content as a child element of the current element.

1
myXmlWriter.Xml(value: ( string | Xml )):XmlWriter

Writes the given XML content as a child element with the specified element name.

1
myXmlWriter.Xml(elementName: string, value: ( string | Xml )):XmlWriter

Parameters

( string | Xml ) value
    The XML content to write. This can be an Xml instance or an XML string.

string elementName
    The name of the element to create as a child.

Returns

The current XmlWriter instance, allowing for method chaining.

Remarks

This method writes the specified XML content as a direct child of the current element. The provided XML is inserted directly without further encoding.

This method creates a new element with the specified name and inserts the given XML content within that element. The provided XML is inserted directly without further encoding.

Examples

Embed an existing node

1
2
3
4
5
6
var writer = $Xml.Create();
writer.StartElement('Request')
    .Xml($Xml.SelectSingle('Customer'))
    .EndElement();
var xml = writer.ToXml();
// '<Request><Customer><Name>Jane Doe</Name>...</Customer></Request>'

Wrap existing markup in a new element

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

See Also