New Features in the XmlReader Class
The Microsoft .NET Framework version 2.0 includes many design and functionality changes to the XmlReader, class.
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.
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.
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:
ReadToDescendant – Advances the reader to the next child element that matches the specified name.
ReadToNextSibling - Advances the reader to the next sibling element that matches the specified name.
ReadToFollowing - Advances the reader to the next following element that matches the specified name.
ReadValueChunk - Reads large streams of text embedded in an XML document in a streaming fashion.
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.