System.Xml.XmlWriter.WriteComment Method

When overridden in a derived class, writes out a comment <!--...--> containing the specified text.

Syntax

public abstract void WriteComment (string text)

Parameters

text
Text to place inside the comment.

Exceptions

TypeReason
ArgumentExceptionThe text would result in a non-well formed XML document.
InvalidOperationExceptionThe XmlWriter.WriteState is WriteState.Closed.

Remarks

If text is either null or String.Empty, this method writes a comment with no data content, for example <!---->.

If text contains an invalid sequence of two dashes "--" the System.Xml.XmlWriter can either throw an ArgumentException (System.Xml.XmlTextWriter objects) or insert a space between the dashes "- -" so that the text is a valid XML comment (System.Xml.XmlWriter objects created by the erload:System.Xml.XmlWriter.Create method).

For the asynchronous version of this method, see XmlWriter.WriteCommentAsync(string).

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0