Skip to main content

Definition

Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml Inheritance: System.Enum

Syntax

Summary

Specifies how a Utf8XmlReader handles comments.

Usage

Set XmlReaderOptions.CommentHandling to choose what a Utf8XmlReader does when it reads a comment. The sample reads one document twice, first with the default options and then with comments skipped (and white space between elements left out):
View the complete sample on GitHub

Remarks

XmlCommentHandling.Allow is the zero value of the enumeration, so it is the default wherever a comment handling value is not set: in XmlReaderOptions and XmlDocumentOptions, whether they are created with new or as default. Comments are kept by default so that XML that is read and written back does not lose them. XmlSerializerOptions.ReadCommentHandling defaults to XmlCommentHandling.Skip, because a comment has no place in an object.

Considerations

  • Allow is the zero value, and the default. new XmlReaderOptions(), default(XmlReaderOptions), a reader created without options, and new XmlReaderState() all report comments. Comments are kept by default so that XML that’s read and written back doesn’t lose them.
  • The serializer’s default is different. XmlSerializerOptions.ReadCommentHandling defaults to Skip, because a comment has no place in an object.
  • A skipped comment is still checked. A comment that contains --, or that’s longer than XmlReaderOptions.MaxCommentByteCount, throws an XmlException under every setting.
  • The setting covers the whole document, including comments before and after the root element.
  • XmlDocument uses the same enumeration. XmlDocumentOptions.CommentHandling also defaults to Allow.

Values

  • CloudNimble.Text.Xml.XmlReaderOptions
  • CloudNimble.Text.Xml.XmlDocumentOptions
  • CloudNimble.Text.Xml.XmlTokenType
  • CloudNimble.Text.Xml.Utf8XmlReader
  • CloudNimble.Text.Xml.XmlWhitespaceHandling