Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
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
)
public XmlTextReader (
	Stream xmlFragment, 
	XmlNodeType fragType, 
	XmlParserContext context
)
public function XmlTextReader (
	xmlFragment : Stream, 
	fragType : XmlNodeType, 
	context : XmlParserContext
)

Parameters

xmlFragment

The stream containing the XML fragment to parse.

fragType

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

context

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.

Exception typeCondition

XmlException

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

ArgumentNullException

xmlFragment is a null reference (Nothing in Visual Basic).

NoteNote

In the Microsoft .NET Framework version 2.0 release, the recommended practice is to create XmlReader instances using the System.Xml.XmlReader.Create method. This allows you to take full advantage of the new features introduced in this release. For more information, see Creating XML Readers.

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 a null reference (Nothing in Visual Basic), the reader checks for a byte-order mark at the beginning of the stream.

  3. If the Encoding property is a null reference (Nothing in Visual Basic), and no byte-order mark is found, the reader assumes the stream is encoded in UTF-8.

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2015 Microsoft