Share via


XmlReader Class

[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]

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

Inheritance Hierarchy

System. . :: . .Object
  System.Xml..::..XmlReader

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

Syntax

'Declaration
Public Class XmlReader _
    Implements IDisposable
public class XmlReader : IDisposable
public ref class XmlReader : IDisposable
type XmlReader =  
    class
        interface IDisposable
    end
public class XmlReader implements IDisposable

The XmlReader type exposes the following members.

Properties

  Name Description
Public property AttributeCount When overridden in a derived class, gets the number of attributes on the current node.
Public property Depth When overridden in a derived class, gets the depth of the current node in the XML document.
Public property EOF When overridden in a derived class, gets a value indicating whether the reader is positioned at the end of the stream.
Public property HasAttributes Gets a value indicating whether the current node has any attributes.
Public property HasValue When overridden in a derived class, gets a value indicating whether the current node can have a Value.
Public property IsEmptyElement When overridden in a derived class, gets a value indicating whether the current node is an empty element (for example, <MyElement/>).
Public property LocalName When overridden in a derived class, gets the local name of the current node.
Public property Name When overridden in a derived class, gets the qualified name of the current node.
Public property NamespaceURI When overridden in a derived class, gets the namespace URI (as defined in the W3C Namespace specification) of the node on which the reader is positioned.
Public property NameTable When overridden in a derived class, gets the XmlNameTable associated with this implementation.
Public property NodeType When overridden in a derived class, gets the type of the current node.
Public property Prefix When overridden in a derived class, gets the namespace prefix associated with the current node.
Public property ReadState When overridden in a derived class, gets the state of the reader.
Public property Value When overridden in a derived class, gets the text value of the current node.
Public property XmlLang When overridden in a derived class, gets the current xml:lang scope.
Public property XmlSpace When overridden in a derived class, gets the current xml:space scope.

Top

Methods

  Name Description
Public method Close When overridden in a derived class, changes the ReadState to Closed.
Public methodStatic member Create(Stream) Creates a new XmlReader instance using the specified stream.
Public methodStatic member Create(Stream, XmlReaderSettings) Creates a new XmlReader instance with the specified stream and XmlReaderSettings object.
Public method Dispose Releases all resources used by the current instance of the XmlReader class.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method 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 GetAttribute(Int32) When overridden in a derived class, gets the value of the attribute with the specified index.
Public method GetAttribute(String) When overridden in a derived class, gets the value of the attribute with the specified Name.
Public method GetAttribute(String, String) When overridden in a derived class, gets the value of the attribute with the specified LocalName and NamespaceURI.
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Public method IsStartElement() () () () Calls MoveToContent and tests if the current content node is a start tag or empty element tag.
Public method 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.
Public method 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.
Public method LookupNamespace When overridden in a derived class, resolves a namespace prefix in the current element's scope.
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method MoveToAttribute(Int32) When overridden in a derived class, moves to the attribute with the specified index.
Public method MoveToAttribute(String) When overridden in a derived class, moves to the attribute with the specified Name.
Public method MoveToAttribute(String, String) When overridden in a derived class, moves to the attribute with the specified LocalName and NamespaceURI.
Public method 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.
Public method MoveToElement When overridden in a derived class, moves to the element that contains the current attribute node.
Public method MoveToFirstAttribute When overridden in a derived class, moves to the first attribute.
Public method MoveToNextAttribute When overridden in a derived class, moves to the next attribute.
Public method Read When overridden in a derived class, reads the next node from the stream.
Public method ReadElementString() () () () Reads a text-only element.
Public method ReadElementString(String) Checks that the Name property of the element found matches the given string before reading a text-only element.
Public method ReadElementString(String, String) Checks that the LocalName and NamespaceURI properties of the element found matches the given strings before reading a text-only element.
Public method ReadEndElement Checks that the current content node is an end tag and advances the reader to the next node.
Public method ReadStartElement() () () () Checks that the current node is an element and advances the reader to the next node.
Public method ReadStartElement(String) Checks that the current content node is an element with the given Name and advances the reader to the next node.
Public method 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.
Public method ReadString When overridden in a derived class, reads the contents of an element or text node as a string.
Public method ReadToDescendant(String) Advances the XmlReader to the next descendant element with the specified qualified name.
Public method ReadToDescendant(String, String) Advances the XmlReader to the next descendant element with the specified local name and namespace URI.
Public method ReadToFollowing(String) Reads until an element with the specified qualified name is found.
Public method ReadToFollowing(String, String) Reads until an element with the specified local name and namespace URI is found.
Public method ReadToNextSibling(String) Advances the XmlReader to the next sibling element with the specified qualified name.
Public method ReadToNextSibling(String, String) Advances the XmlReader to the next sibling element with the specified local name and namespace URI.
Public method Skip Skips the children of the current node.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)

Top

Remarks

XmlReader provides forward-only, read-only access to a stream of XML data. The XmlReader class conforms to the W3C Extensible Markup Language (XML) 1.0 and the Namespaces in XML recommendations.

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.

XmlReader 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 the reader is in error state.

Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

See Also

Reference

System.Xml Namespace