Definition
Assembly: CloudNimble.XmlEssentials.dll Namespace: CloudNimble.Text.Xml Inheritance: System.EnumSyntax
Summary
Specifies how a Utf8XmlReader handles whitespace-only text between elements.Usage
SetXmlReaderOptions.WhitespaceHandling to choose what a Utf8XmlReader does with text that is only white space and sits between elements. That’s the indentation of a formatted document.
White-space-only text that is content is reported under every setting: the whole content of an element (````csharp
````), text after other text or a CDATA section in the same element (mixed content), and anything inside an element where
xml:space="preserve" is in force.
With the default, the document below produces three Text tokens for the indentation inside Order. With Insignificant, they’re gone:
Remarks
Whitespace inside a leaf element’s value is always significant.<n> a </n> is the value " a " regardless of this setting.
XmlWhitespaceHandling.Significant is the zero value of the enumeration, so it is the default wherever a
whitespace handling value is not set: in XmlReaderOptions and
XmlDocumentOptions, whether they are created with new or as
default. Whitespace between elements, such as indentation, is kept by default so
that XML that is read and written back does not change its layout.
XmlSerializerOptions.WhitespaceHandling defaults to XmlWhitespaceHandling.Insignificant, because
indentation has no place in an object.
Considerations
Significantis the zero value, and the default.new XmlReaderOptions(),default(XmlReaderOptions), and a reader created without options all report white space between elements. It’s kept by default so that XML that’s read and written back doesn’t change its layout.- Set
Insignificantin a loop that only wants data. Otherwise the token after a start tag that has child elements is usually aTexttoken that holds indentation. - The serializer’s default is different.
XmlSerializerOptions.WhitespaceHandlingdefaults toInsignificant, because indentation has no place in an object. - The setting never changes a value. White space inside an element’s text is part of the value under every setting:
<Name> Ada </Name>is" Ada ". The reader doesn’t trim. Line ends are read as a line feed under every setting, as XML requires. - Only indentation is skipped. Under
InsignificantandNone, white-space-only text is still aTexttoken when it’s the whole content of its element, when its element already has text or a CDATA section before it, as in the space between</b>and*in<p>a **b** <i>c*</p>, or whenxml:space="preserve"applies.xml:space="preserve"holds for the element and everything inside it, until an element setsxml:space="default". - Reading in blocks doesn’t change the result.
XmlReaderStatecarriesxml:spaceand whether each open element has text, so a document split across blocks reports the same white space as one read whole. - White space outside the root element is never reported. The line break after the XML declaration and anything after the root’s end tag are skipped under every setting.
Nonerejects indented documents. Use it only when the producer is known to write no indentation and anything else is an error. It accepts the white space that is content, as listed above.XmlDocumentuses the same enumeration.XmlDocumentOptions.WhitespaceHandlingalso defaults toSignificant.
Values
Related APIs
- CloudNimble.Text.Xml.XmlReaderOptions
- CloudNimble.Text.Xml.XmlDocumentOptions
- CloudNimble.Text.Xml.XmlTokenType
- CloudNimble.Text.Xml.Utf8XmlReader
- CloudNimble.Text.Xml.XmlCommentHandling