Property Settings on XmlReader

The XmlReader class has properties that can be modified while reading and other properties that, if changed after the reading has begun, do not have the new setting affect the reading. These properties need to be set to their correct value before initiating the reading if the default values are not appropriate. However, some properties can be modified after the reading has started. For properties that cannot be set after calling Read, the readers throw an exception.

The table below shows what properties can be modified once reading has begun.

Class

Property

Can be modified

XmlTextReader

Namespaces

no

XmlTextReader

WhitespaceHandling

yes

XmlTextReader

Normalization

yes

XmlTextReader

XmlResolver

yes

XmlValidatingReader

Namespaces

no

XmlValidatingReader

EntityHandling

yes

XmlValidatingReader

XmlResolver

yes

XmlValidatingReader

ValidationType

no

The XmlValidatingReader propagates the XmlResolver property to the contained XmlTextReader class. The XmlNodeReader class has no properties that can be set.

Normalization and XmlResolver Settings

Note

In the .NET Framework version 2.0 release, the recommended practice is to create XmlReader instances using the XmlReaderSettings class and the Create method. This allows you to take full advantage of all the new features introduced in the .NET Framework 2.0. XmlReader objects created by the Create method perform normalization, add default attributes, and expand entities by default. For more information, see Creating XML Readers.

The following table describes how the XmlResolver and Normalization properties on the various readers can be set to achieve each scenario.

The Normalization property, when set to true, normalizes the end-of-line characters in text and white space nodes and also normalizes the attribute values according to their type.

The XmlResolver property is used for resolving external resources named by a Uniform Resource Identifier (URI), such as an external document type definition (DTD) or locating a schema. For more information on using the XmlResolver property with the different readers, see Resolving Resources Using the XmlResolver.

Scenario

XmlResolver

Normalization property

Does not need any DTD or schema support, or full conformance with XML normalization and default attributes..

Set to null reference.

Set to false and use the XmlTextReader class.

Requires document to be well-formed, including external entities and DocTypes with a supplied DTD.

Set to non-null reference. All external entities must be resolvable.

Set to true on XmlTextReader before being passed to XmlValidatingReader.

Needs document to be well-formed and needs the XML to be valid according to the DTD.

Set to non-null reference. All external entities must be resolvable.

Set to true on XmlTextReader before being passed to XmlValidatingReader.

Needs document to be well-formed and needs schema validation.

Set to non-null reference. All external entities must be resolvable.

Set to true on XmlTextReader before being passed to XmlValidatingReader.

Needs document to be well-formed when streaming XML data from an XmlNode.

Not available.

Not available.

See Also

Concepts

Reading XML with the XmlReader

Other Resources

Using the XmlReader Class