Provides forward-only, read-only access to XML data.
The XmlReader class provides a high-performance, forward-only, read-only mechanism for reading XML data. It is designed for scenarios where you need to process large XML documents efficiently without loading the entire document into memory. This class supports various XML conformance levels and provides fine-grained control over how XML is read.
XmlReader is an abstract class. To use it, you typically create an instance of one of its derived classes, such as XmlTextReader (for reading from text-based sources) or XmlDictionaryReader (for optimized reading of binary XML). The XmlReader.Create method is the recommended way to instantiate an XmlReader, as it can automatically detect the appropriate reader implementation based on the input stream or URI.
Key features of XmlReader include:
XmlReader.public abstract class XmlReader : IDisposable
System.Object
System.Xml.XmlReader
System.Xml.XmlDictionaryReader
System.Xml.XmlTextReader
XmlReader is an abstract class and cannot be instantiated directly. Use the static XmlReader.Create method to create an instance.
| Name | Description |
|---|---|
AttributeCount |
Gets the number of attributes on the current node. |
BaseURI |
Gets the base URI of the current node. |
CanReadBinaryContent |
Gets a value indicating whether the reader can read binary data. |
CanResolveEntity |
Gets a value indicating whether the reader can resolve external entities. |
Depth |
Gets the depth of the current node in the XML document. |
EOF |
Gets a value indicating whether the reader is at the end of the stream. |
HasAttributes |
Gets a value indicating whether the current node has attributes. |
HasValue |
Gets a value indicating whether the current node has a value. |
IsDefault |
Gets a value indicating whether the value of the current node is from an attribute that was defaulted. |
IsEmptyElement |
Gets a value indicating whether the current node is an empty element (e.g., <MyElement/>). |
Item(Int32) |
Gets the value of the attribute with the specified index. |
Item(String) |
Gets the value of the attribute with the specified local name. |
Item(String, String) |
Gets the value of the attribute with the specified local name and namespace. |
LocalName |
Gets the local name of the current node. |
Name |
Gets the qualified name of the current node. |
NamespaceURI |
Gets the namespace URI of the current node. |
NameTable |
Gets the XmlNameTable to use for tokenizing names. |
NodeType |
Gets the type of the current node. |
Prefix |
Gets the namespace prefix of the current node. |
QuoteChar |
Gets the character used to quote attribute values. |
ReadState |
Gets the state of the reader. |
Value |
Gets the text value of the current node. |
XmlLang |
Gets the current xml:lang attribute value. |
XmlSpace |
Gets the current xml:space attribute value. |
Closes the stream to the underlying sources and releases the resources associated with the reader.
Gets the value of the attribute with the specified index.
Gets the value of the attribute with the specified local name.
Gets the value of the attribute with the specified local name and namespace.
Gets the text value of the current node.
Resolves the namespace prefix on the current node, or for the reader itself if it is not on an element node.
Moves to the attribute with the specified index.
Moves to the attribute with the specified local name.
Moves to the attribute with the specified local name and namespace.
Moves to the element that contains the current attribute node.
Moves to the first attribute of the current node.
Moves to the next attribute of the current node.
Reads the next node from the XML stream.
Reads the attribute value of the current node.
Reads until the current node is an end element or a stream level is reached.
Reads the text content of the current element and moves the reader to the next sibling.
Reads the text content of an element with the specified local name and moves the reader to the next sibling.
Reads the text content of an element with the specified local name and namespace and moves the reader to the next sibling.
Reads the content of the current node (including markup) and returns it as a string.
Reads the outer XML content of the current node and returns it as a string.
Reads the text content of the current node and moves to the next node.
Reads until the next node with the specified local name is encountered.
Reads until the next node with the specified local name and namespace is encountered.
Reads until the next sibling node with the specified local name is encountered.
Reads until the next sibling node with the specified local name and namespace is encountered.
Reads until the next text node is encountered.
Reads until the current node is an element or a stream level is reached.
Reads the start element with the specified local name.
Reads the start element with the specified local name and namespace.
Resolves the current DTD entity.
| Exception Type | Condition |
|---|---|
ArgumentException |
The XmlReaderSettings object is invalid. |
XmlException |
An error occurred while parsing the XML. |
IOException |
An I/O error occurred. |
OutOfMemoryException |
Not enough memory is available to process the request. |