XmlValidatingReader Constructor (Stream, XmlNodeType, XmlParserContext)

XmlValidatingReader Constructor (Stream, XmlNodeType, XmlParserContext)


Initializes a new instance of the XmlValidatingReader class with the specified values.

Namespace:   System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public XmlValidatingReader(
	Stream xmlFragment,
	XmlNodeType fragType,
	XmlParserContext context


Type: System.IO.Stream

The stream containing the XML fragment to parse.

Type: System.Xml.XmlNodeType

The XmlNodeType of the XML fragment. This determines what the fragment can contain (see table below).

Type: System.Xml.XmlParserContext

The XmlParserContext in which the XML fragment is to be parsed. This includes the XmlNameTable to use, encoding, namespace scope, current xml:lang, and xml:space scope.

Exception Condition

fragType is not one of the node types listed in the table below.


The XmlValidatingReader class is obsolete in .NET Framework 2.0. You can create a validating XmlReader instance by using the XmlReaderSettings class and the Create method. For more information, see the Remarks section of the XmlReader reference page.

This constructor parses the given string as a fragment of XML. If the XML fragment is an element or attribute, you can bypass the root level rules for well-formed XML documents.

The following table lists valid values for fragType and how the reader parses each of the different node types.


Fragment May Contain


Any valid element content (for example, any combination of elements, comments, processing instructions, cdata, text, and entity references).


The value of an attribute (the part inside the quotes).


The contents of an entire XML document; this enforces document level rules.

The reader uses the following steps to determine the encoding of the stream:

  1. Checks the XmlParserContext.Encoding property to determine the encoding.

  2. If the Encoding property is null, the reader checks for a byte-order mark at the beginning of the stream.

  3. If the Encoding property is null, and no byte-order mark is found, the reader assumes the stream is encoded in UTF-8.

If this reader will be validating using document type definition (DTD) (that is, ValidationType is set to ValidationType.DTD or ValidationType.Auto), the XmlParserContext specified in the constructor must supply all the necessary DocumentType information.


It is not possible to validate a fragment by using a DTD. By definition a DTD requires an entire document to be loaded for validation.

If this reader will be validating by using XML-Data Reduced (XDR) or XML Schema definition language (XSD) schemas, use the Schemas property to specify the XmlSchemaCollection that contains the schemas (that is, the XmlParserContext does not need to supply the DocumentType information).

.NET Framework
Available since 1.1
Return to top
© 2015 Microsoft