Reading XML Using Concrete XmlReader Implementaions

In the .NET Framework version 2.0 XmlReader instances can be created using the Create method. This is the recommended way to obtain XmlReader instances.

XmlReader Implementations

However, there may be cases where you may wish to use one of the concrete XmlReader implementations. Implementations of the XmlReader class extend the base class and vary in their design to support different scenario needs. The following table describes the implementations of the XmlReader class.

Class

Description

XmlTextReader

Reads character streams. It is a forward-only reader that has methods that return data on content and node types. There is no document type definition (DTD) or schema support. If the XML document contains a DTD, the DTD will be parsed, but it will not be used for validation or for adding default attributes.

In the .NET Framework 2.0, the XmlTextReader class can be used if you do not want entities to be expanded, or if you do not want to have new lines normalized. In all other cases, it is recommended that you create an XmlReader instance using the Create method. For more information, see Creating XML Readers.

XmlNodeReader

Provides an XmlReader over an XML Document Object Model (DOM) API, like the XmlNode tree. Takes in an XmlNode and returns whatever nodes it finds in the DOM tree, including entity reference nodes. There is no DTD or schema validation support; however, it can resolve entities defined in DTDs.

XmlValidatingReader

Provides a fully compliant validating or non-validating XML parser with DTD, XML Schema definition language (XSD) schema or XML-Data Reduced (XDR) schema support. Takes an XmlTextReader and layers validation services on top.

In the .NET Framework 2.0, the XmlValidatingReader class can be used if you must validate using an XDR schema. In all other cases, create an XmlReader instance using the Create method. For more information see Validating XML Data with XmlReader.

Note

The XmlValidatingReader class is obsolete in the .NET Framework 2.0.

See Also

Concepts

Reading XML with the XmlReader

Creating XML Readers