This documentation is archived and is not being maintained.

New Features in the XmlReader Class

.NET Framework 3.5

The Microsoft .NET Framework version 2.0 includes many design and functionality changes to the XmlReader, class.

In this release, the Create method is the preferred mechanism for obtaining XmlReader instances. The Create method uses the XmlReaderSettings class to specify which features the XmlReader instance should support.

For more information, see Creating XML Readers.

XmlReader objects created by the Create method can enforce validation using a document type definition (DTD) or Schema definition language (XSD) schema. The XmlReaderSettings.ValidationType property determines whether the XmlReader instance enforces validation. The XmlReaderSettings.ValidationFlags property configures optional validation settings. The XmlSchemaSet class is used to cache XML Schemas.


The XmlValidatingReader and XmlSchemaCollection classes are obsolete in the .NET Framework 2.0.

For more information, see Validating XML Data with XmlReader.

XmlReader objects created by the Create method are, by default, more conformant than the XmlTextReader implementation. XmlReader objects created by the Create method support the following features by default:

  • Normalize new line characters.

  • Expand entities.

  • Add default attributes.

The XmlReaderSettings.CheckCharacters and XmlReaderSettings.ConformanceLevel properties allow you to specify the type of conformance checks you want to enable on the created XmlReader object. For more information, see Data Conformance Checking with XmlReader.

Provides support for retrieving XML Schema definition language (XSD) schema information and permits callers to request values as simple-typed common language runtime (CLR) values.

The ReadContentAs and ReadElementContentAs methods can read content as system types rather than strings. These new methods allow users to get values in the representation that is most appropriate for the coding job without having to manually perform value conversions and parsing.

For more information, see Reading Typed Data.

The XmlReader class includes new methods that should make it easier to parse XML data:

You can create an XmlReader object that prohibits document type definition (DTD) processing. Disabling DTD processing can be useful in preventing certain denial of service attacks. When DTD processing is disabled, the XmlReader object throws an XmlException when any DTD content is encountered. By default, DTD processing is disabled. To enable DTD processing, set the XmlReaderSettings.ProhibitDtd property to false before creating the XmlReader.


The ProhibitDtd property is also available on the XmlTextReader class.

XmlReader objects created by the Create method expand all entities automatically. An exception is thrown if entities are encountered that cannot be resolved.