Export (0) Print
Expand All

XmlTextReader Constructor (Stream, XmlNodeType, XmlParserContext)

Initializes a new instance of the XmlTextReader class with the specified stream, XmlNodeType, and XmlParserContext.

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

public XmlTextReader(
	Stream xmlFragment,
	XmlNodeType fragType,
	XmlParserContext context
)

Parameters

xmlFragment
Type: System.IO.Stream

The stream containing the XML fragment to parse.

fragType
Type: System.Xml.XmlNodeType

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

context
Type: System.Xml.XmlParserContext

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

ExceptionCondition
XmlException

fragType is not an Element, Attribute, or Document XmlNodeType.

ArgumentNullException

xmlFragment is null.

NoteNote

Starting with the .NET Framework 2.0, we recommend that you create XmlReader instances by using the XmlReader.Create method to take advantage of new functionality.

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.

XmlNodeType

Fragment May Contain

Element

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

An XML declaration can also be supplied. This allows you to specify the encoding for the XML fragment, rather than having to set it on the XmlParserContext object.

Attribute

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

Document

The contents of an entire XML document. This enforces document level rules.

The reader uses the following 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.

.NET Framework

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0, 1.1

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

XNA Framework

Supported in: 3.0, 2.0, 1.0
Show:
© 2015 Microsoft