1 out of 5 rated this helpful - Rate this topic

XmlTextReader Class

Represents a reader that provides fast, non-cached, forward-only access to XML data.

System.Object
  System.Xml.XmlReader
    System.Xml.XmlTextReader

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
[PermissionSetAttribute(SecurityAction.InheritanceDemand, Name = "FullTrust")]
public class XmlTextReader : XmlReader, 
	IXmlLineInfo, IXmlNamespaceResolver

The XmlTextReader type exposes the following members.

  Name Description
Protected method Supported by the XNA Framework XmlTextReader() Initializes a new instance of the XmlTextReader.
Public method Supported by the XNA Framework XmlTextReader(Stream) Initializes a new instance of the XmlTextReader class with the specified stream.
Public method Supported by the XNA Framework XmlTextReader(String) Initializes a new instance of the XmlTextReader class with the specified file.
Public method Supported by the XNA Framework XmlTextReader(TextReader) Initializes a new instance of the XmlTextReader class with the specified TextReader.
Protected method Supported by the XNA Framework XmlTextReader(XmlNameTable) Infrastructure. Initializes a new instance of the XmlTextReader class with the specified XmlNameTable.
Public method Supported by the XNA Framework XmlTextReader(Stream, XmlNameTable) Initializes a new instance of the XmlTextReader class with the specified stream and XmlNameTable.
Public method Supported by the XNA Framework XmlTextReader(String, Stream) Initializes a new instance of the XmlTextReader class with the specified URL and stream.
Public method Supported by the XNA Framework XmlTextReader(String, TextReader) Initializes a new instance of the XmlTextReader class with the specified URL and TextReader.
Public method Supported by the XNA Framework XmlTextReader(String, XmlNameTable) Initializes a new instance of the XmlTextReader class with the specified file and XmlNameTable.
Public method Supported by the XNA Framework XmlTextReader(TextReader, XmlNameTable) Initializes a new instance of the XmlTextReader class with the specified TextReader and XmlNameTable.
Public method Supported by the XNA Framework XmlTextReader(Stream, XmlNodeType, XmlParserContext) Initializes a new instance of the XmlTextReader class with the specified stream, XmlNodeType, and XmlParserContext.
Public method Supported by the XNA Framework XmlTextReader(String, Stream, XmlNameTable) Initializes a new instance of the XmlTextReader class with the specified URL, stream and XmlNameTable.
Public method Supported by the XNA Framework XmlTextReader(String, TextReader, XmlNameTable) Initializes a new instance of the XmlTextReader class with the specified URL, TextReader and XmlNameTable.
Public method Supported by the XNA Framework XmlTextReader(String, XmlNodeType, XmlParserContext) Initializes a new instance of the XmlTextReader class with the specified string, XmlNodeType, and XmlParserContext.
Top
  Name Description
Public property Supported by the XNA Framework AttributeCount Gets the number of attributes on the current node. (Overrides XmlReader.AttributeCount.)
Public property Supported by the XNA Framework BaseURI Gets the base URI of the current node. (Overrides XmlReader.BaseURI.)
Public property Supported by the XNA Framework CanReadBinaryContent Gets a value indicating whether the XmlTextReader implements the binary content read methods. (Overrides XmlReader.CanReadBinaryContent.)
Public property Supported by the XNA Framework CanReadValueChunk Gets a value indicating whether the XmlTextReader implements the ReadValueChunk method. (Overrides XmlReader.CanReadValueChunk.)
Public property Supported by the XNA Framework CanResolveEntity Gets a value indicating whether this reader can parse and resolve entities. (Overrides XmlReader.CanResolveEntity.)
Public property Supported by the XNA Framework Depth Gets the depth of the current node in the XML document. (Overrides XmlReader.Depth.)
Public property DtdProcessing Gets or sets the DtdProcessing enumeration.
Public property Supported by the XNA Framework Encoding Gets the encoding of the document.
Public property Supported by the XNA Framework EntityHandling Gets or sets a value that specifies how the reader handles entities.
Public property Supported by the XNA Framework EOF Gets a value indicating whether the reader is positioned at the end of the stream. (Overrides XmlReader.EOF.)
Public property Supported by the XNA Framework HasAttributes Gets a value indicating whether the current node has any attributes. (Inherited from XmlReader.)
Public property Supported by the XNA Framework HasValue Gets a value indicating whether the current node can have a Value other than String.Empty. (Overrides XmlReader.HasValue.)
Public property Supported by the XNA Framework IsDefault Gets a value indicating whether the current node is an attribute that was generated from the default value defined in the DTD or schema. (Overrides XmlReader.IsDefault.)
Public property Supported by the XNA Framework IsEmptyElement Gets a value indicating whether the current node is an empty element (for example, <MyElement/>). (Overrides XmlReader.IsEmptyElement.)
Public property Supported by the XNA Framework Item[Int32] When overridden in a derived class, gets the value of the attribute with the specified index. (Inherited from XmlReader.)
Public property Supported by the XNA Framework Item[String] When overridden in a derived class, gets the value of the attribute with the specified Name. (Inherited from XmlReader.)
Public property Supported by the XNA Framework Item[String, String] When overridden in a derived class, gets the value of the attribute with the specified LocalName and NamespaceURI. (Inherited from XmlReader.)
Public property Supported by the XNA Framework LineNumber Gets the current line number.
Public property Supported by the XNA Framework LinePosition Gets the current line position.
Public property Supported by the XNA Framework LocalName Gets the local name of the current node. (Overrides XmlReader.LocalName.)
Public property Supported by the XNA Framework Name Gets the qualified name of the current node. (Overrides XmlReader.Name.)
Public property Supported by the XNA Framework Namespaces Gets or sets a value indicating whether to do namespace support.
Public property Supported by the XNA Framework NamespaceURI Gets the namespace URI (as defined in the W3C Namespace specification) of the node on which the reader is positioned. (Overrides XmlReader.NamespaceURI.)
Public property Supported by the XNA Framework NameTable Gets the XmlNameTable associated with this implementation. (Overrides XmlReader.NameTable.)
Public property Supported by the XNA Framework NodeType Gets the type of the current node. (Overrides XmlReader.NodeType.)
Public property Supported by the XNA Framework Normalization Gets or sets a value indicating whether to normalize white space and attribute values.
Public property Supported by the XNA Framework Prefix Gets the namespace prefix associated with the current node. (Overrides XmlReader.Prefix.)
Public property ProhibitDtd Obsolete. Gets or sets a value indicating whether to allow DTD processing. This property is obsolete. Use DtdProcessing instead.
Public property Supported by the XNA Framework QuoteChar Gets the quotation mark character used to enclose the value of an attribute node. (Overrides XmlReader.QuoteChar.)
Public property Supported by the XNA Framework ReadState Gets the state of the reader. (Overrides XmlReader.ReadState.)
Public property Supported by the XNA Framework SchemaInfo Gets the schema information that has been assigned to the current node as a result of schema validation. (Inherited from XmlReader.)
Public property Supported by the XNA Framework Settings Gets the XmlReaderSettings object used to create this XmlReader instance. (Inherited from XmlReader.)

In XNA Framework, this member is overridden by Settings.
Public property Supported by the XNA Framework Value Gets the text value of the current node. (Overrides XmlReader.Value.)
Public property Supported by the XNA Framework ValueType Gets The Common Language Runtime (CLR) type for the current node. (Inherited from XmlReader.)
Public property Supported by the XNA Framework WhitespaceHandling Gets or sets a value that specifies how white space is handled.
Public property Supported by the XNA Framework XmlLang Gets the current xml:lang scope. (Overrides XmlReader.XmlLang.)
Public property Supported by the XNA Framework XmlResolver Sets the XmlResolver used for resolving DTD references.
Public property Supported by the XNA Framework XmlSpace Gets the current xml:space scope. (Overrides XmlReader.XmlSpace.)
Top
  Name Description
Public method Supported by the XNA Framework Close Changes the ReadState to Closed. (Overrides XmlReader.Close().)
Protected method Supported by the XNA Framework Dispose(Boolean) Releases the unmanaged resources used by the XmlReader and optionally releases the managed resources. (Inherited from XmlReader.)
Public method Supported by the XNA Framework Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Supported by the XNA Framework Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method Supported by the XNA Framework GetAttribute(Int32) Gets the value of the attribute with the specified index. (Overrides XmlReader.GetAttribute(Int32).)
Public method Supported by the XNA Framework GetAttribute(String) Gets the value of the attribute with the specified name. (Overrides XmlReader.GetAttribute(String).)
Public method Supported by the XNA Framework GetAttribute(String, String) Gets the value of the attribute with the specified local name and namespace URI. (Overrides XmlReader.GetAttribute(String, String).)
Public method Supported by the XNA Framework GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method Supported by the XNA Framework GetNamespacesInScope Gets a collection that contains all namespaces currently in-scope.
Public method Supported by the XNA Framework GetRemainder Gets the remainder of the buffered XML.
Public method Supported by the XNA Framework GetType Gets the Type of the current instance. (Inherited from Object.)
Public method Supported by the XNA Framework HasLineInfo Gets a value indicating whether the class can return line information.
Public method Supported by the XNA Framework IsStartElement() Calls MoveToContent and tests if the current content node is a start tag or empty element tag. (Inherited from XmlReader.)
Public method Supported by the XNA Framework IsStartElement(String) Calls MoveToContent and tests if the current content node is a start tag or empty element tag and if the Name property of the element found matches the given argument. (Inherited from XmlReader.)
Public method Supported by the XNA Framework IsStartElement(String, String) Calls MoveToContent and tests if the current content node is a start tag or empty element tag and if the LocalName and NamespaceURI properties of the element found match the given strings. (Inherited from XmlReader.)
Public method Supported by the XNA Framework LookupNamespace Resolves a namespace prefix in the current element's scope. (Overrides XmlReader.LookupNamespace(String).)
Protected method Supported by the XNA Framework MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method Supported by the XNA Framework MoveToAttribute(Int32) Moves to the attribute with the specified index. (Overrides XmlReader.MoveToAttribute(Int32).)
Public method Supported by the XNA Framework MoveToAttribute(String) Moves to the attribute with the specified name. (Overrides XmlReader.MoveToAttribute(String).)
Public method Supported by the XNA Framework MoveToAttribute(String, String) Moves to the attribute with the specified local name and namespace URI. (Overrides XmlReader.MoveToAttribute(String, String).)
Public method Supported by the XNA Framework MoveToContent Checks whether the current node is a content (non-white space text, CDATA, Element, EndElement, EntityReference, or EndEntity) node. If the node is not a content node, the reader skips ahead to the next content node or end of file. It skips over nodes of the following type: ProcessingInstruction, DocumentType, Comment, Whitespace, or SignificantWhitespace. (Inherited from XmlReader.)
Public method Supported by the XNA Framework MoveToElement Moves to the element that contains the current attribute node. (Overrides XmlReader.MoveToElement().)
Public method Supported by the XNA Framework MoveToFirstAttribute Moves to the first attribute. (Overrides XmlReader.MoveToFirstAttribute().)
Public method Supported by the XNA Framework MoveToNextAttribute Moves to the next attribute. (Overrides XmlReader.MoveToNextAttribute().)
Public method Supported by the XNA Framework Read Reads the next node from the stream. (Overrides XmlReader.Read().)
Public method Supported by the XNA Framework ReadAttributeValue Parses the attribute value into one or more Text, EntityReference, or EndEntity nodes. (Overrides XmlReader.ReadAttributeValue().)
Public method Supported by the XNA Framework ReadBase64 Decodes Base64 and returns the decoded binary bytes.
Public method Supported by the XNA Framework ReadBinHex Decodes BinHex and returns the decoded binary bytes.
Public method Supported by the XNA Framework ReadChars Reads the text contents of an element into a character buffer. This method is designed to read large streams of embedded text by calling it successively.
Public method Supported by the XNA Framework ReadContentAs Reads the content as an object of the type specified. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadContentAsBase64 Reads the content and returns the Base64 decoded binary bytes. (Overrides XmlReader.ReadContentAsBase64(Byte[], Int32, Int32).)
Public method Supported by the XNA Framework ReadContentAsBinHex Reads the content and returns the BinHex decoded binary bytes. (Overrides XmlReader.ReadContentAsBinHex(Byte[], Int32, Int32).)
Public method Supported by the XNA Framework ReadContentAsBoolean Reads the text content at the current position as a Boolean. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadContentAsDateTime Reads the text content at the current position as a DateTime object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadContentAsDecimal Reads the text content at the current position as a Decimal object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadContentAsDouble Reads the text content at the current position as a double-precision floating-point number. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadContentAsFloat Reads the text content at the current position as a single-precision floating point number. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadContentAsInt Reads the text content at the current position as a 32-bit signed integer. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadContentAsLong Reads the text content at the current position as a 64-bit signed integer. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadContentAsObject Reads the text content at the current position as an Object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadContentAsString Reads the text content at the current position as a String object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAs(Type, IXmlNamespaceResolver) Reads the element content as the requested type. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAs(Type, IXmlNamespaceResolver, String, String) Checks that the specified local name and namespace URI matches that of the current element, then reads the element content as the requested type. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsBase64 Reads the element and decodes the Base64 content. (Overrides XmlReader.ReadElementContentAsBase64(Byte[], Int32, Int32).)
Public method Supported by the XNA Framework ReadElementContentAsBinHex Reads the element and decodes the BinHex content. (Overrides XmlReader.ReadElementContentAsBinHex(Byte[], Int32, Int32).)
Public method Supported by the XNA Framework ReadElementContentAsBoolean() Reads the current element and returns the contents as a Boolean object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsBoolean(String, String) Checks that the specified local name and namespace URI matches that of the current element, then reads the current element and returns the contents as a Boolean object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsDateTime() Reads the current element and returns the contents as a DateTime object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsDateTime(String, String) Checks that the specified local name and namespace URI matches that of the current element, then reads the current element and returns the contents as a DateTime object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsDecimal() Reads the current element and returns the contents as a Decimal object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsDecimal(String, String) Checks that the specified local name and namespace URI matches that of the current element, then reads the current element and returns the contents as a Decimal object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsDouble() Reads the current element and returns the contents as a double-precision floating-point number. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsDouble(String, String) Checks that the specified local name and namespace URI matches that of the current element, then reads the current element and returns the contents as a double-precision floating-point number. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsFloat() Reads the current element and returns the contents as single-precision floating-point number. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsFloat(String, String) Checks that the specified local name and namespace URI matches that of the current element, then reads the current element and returns the contents as a single-precision floating-point number. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsInt() Reads the current element and returns the contents as a 32-bit signed integer. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsInt(String, String) Checks that the specified local name and namespace URI matches that of the current element, then reads the current element and returns the contents as a 32-bit signed integer. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsLong() Reads the current element and returns the contents as a 64-bit signed integer. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsLong(String, String) Checks that the specified local name and namespace URI matches that of the current element, then reads the current element and returns the contents as a 64-bit signed integer. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsObject() Reads the current element and returns the contents as an Object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsObject(String, String) Checks that the specified local name and namespace URI matches that of the current element, then reads the current element and returns the contents as an Object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsString() Reads the current element and returns the contents as a String object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementContentAsString(String, String) Checks that the specified local name and namespace URI matches that of the current element, then reads the current element and returns the contents as a String object. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementString() Reads a text-only element. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementString(String) Checks that the Name property of the element found matches the given string before reading a text-only element. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadElementString(String, String) Checks that the LocalName and NamespaceURI properties of the element found matches the given strings before reading a text-only element. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadEndElement Checks that the current content node is an end tag and advances the reader to the next node. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadInnerXml When overridden in a derived class, reads all the content, including markup, as a string. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadOuterXml When overridden in a derived class, reads the content, including markup, representing this node and all its children. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadStartElement() Checks that the current node is an element and advances the reader to the next node. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadStartElement(String) Checks that the current content node is an element with the given Name and advances the reader to the next node. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadStartElement(String, String) Checks that the current content node is an element with the given LocalName and NamespaceURI and advances the reader to the next node. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadString Reads the contents of an element or a text node as a string. (Overrides XmlReader.ReadString().)
Public method Supported by the XNA Framework ReadSubtree Returns a new XmlReader instance that can be used to read the current node, and all its descendants. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadToDescendant(String) Advances the XmlReader to the next descendant element with the specified qualified name. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadToDescendant(String, String) Advances the XmlReader to the next descendant element with the specified local name and namespace URI. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadToFollowing(String) Reads until an element with the specified qualified name is found. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadToFollowing(String, String) Reads until an element with the specified local name and namespace URI is found. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadToNextSibling(String) Advances the XmlReader to the next sibling element with the specified qualified name. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadToNextSibling(String, String) Advances the XmlReader to the next sibling element with the specified local name and namespace URI. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ReadValueChunk Reads large streams of text embedded in an XML document. (Inherited from XmlReader.)
Public method Supported by the XNA Framework ResetState Resets the state of the reader to ReadState.Initial.
Public method Supported by the XNA Framework ResolveEntity Resolves the entity reference for EntityReference nodes. (Overrides XmlReader.ResolveEntity().)
Public method Supported by the XNA Framework Skip Skips the children of the current node. (Overrides XmlReader.Skip().)
Public method Supported by the XNA Framework ToString Returns a string that represents the current object. (Inherited from Object.)
Top
Note Note

In the .NET Framework version 2.0 release, the recommended practice is to create XmlReader instances using the 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.

XmlTextReader provides forward-only, read-only access to a stream of XML data. The current node refers to the node on which the reader is positioned. The reader is advanced using any of the read methods and properties reflect the value of the current node.

This class implements XmlReader and conforms to the W3C Extensible Markup Language (XML) 1.0 and the Namespaces in XML recommendations. XmlTextReader provides the following functionality:

  • Enforces the rules of well-formed XML.

  • XmlTextReader does not provide data validation.

  • Checks that DocumentType nodes are well-formed. XmlTextReader checks the DTD for well-formedness, but does not validate using the DTD.

  • For nodes where NodeType is XmlNodeType.EntityReference, a single empty EntityReference node is returned (that is, the Value property is String.Empty).

Note Note

The actual declarations of entities in the DTD are called Entity nodes. When you refer to these nodes in your data, they are called EntityReference nodes.

  • Does not expand default attributes.

Because the XmlTextReader does not perform the extra checks required for data validation, it provides a fast well-formedness parser.

To perform data validation, use a validating XmlReader. For more information, see Validating XML Data with XmlReader.

To read XML data from an XmlDocument, use XmlNodeReader.

XmlTextReader throws an XmlException on XML parse errors. After an exception is thrown the state of the reader is not predictable. For example, the reported node type may be different than the actual node type of the current node. Use the ReadState property to check whether a reader is in error state.

For further discussion on the XmlReader classes, see Reading XML with the XmlReader.

Security Considerations

The following are things to consider when using the XmlTextReader class.

  • Exceptions thrown the XmlTextReader can disclose path information that you do not want bubbled up to the application. Your applications must catch exceptions and process them appropriately.

  • DTD processing is enabled by default. Disable DTD processing if you are concerned about Denial of Service issues or if you are dealing with untrusted sources. Set the DtdProcessing property to Prohibit to disable DTD processing.

    If you have DTD processing enabled, you can use the XmlSecureResolver to restrict the resources that the XmlTextReader can access. You can also design your application so that the XML processing is memory and time constrained. For example, configure time-out limits in your ASP.NET application.

  • XML data can include references to external resources such as a DTD file. By default external resources are resolved using an XmlUrlResolver object with no user credentials. You can secure this further by doing one of the following:

  • XML data can contain a large number of attributes, namespace declarations, nested elements and so on that require a substantial amount of time to process. To limit the size of the input that is sent to the XmlTextReader, create a custom IStream implementation and supply it the XmlTextReader.

  • The ReadValueChunk method can be used to handle large streams of data. This method reads a small number of characters at a time instead of allocating a single string for the whole value.

  • By default general entities are not expanded. General entities are expanded when you call the ResolveEntity method.

Notes to Inheritors

This class has an inheritance demand. Full trust is required to inherit from XmlTextReader. See Inheritance Demands for more information.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ
Timeout
It should be a bug that this class does not expose the Timeout property in the underlying HttpWebRequest.