Επεξεργασία

Κοινή χρήση μέσω


XmlReader Class

Definition

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

public ref class XmlReader abstract : IDisposable
public ref class XmlReader abstract
public abstract class XmlReader : IDisposable
public abstract class XmlReader
type XmlReader = class
    interface IDisposable
type XmlReader = class
Public MustInherit Class XmlReader
Implements IDisposable
Public MustInherit Class XmlReader
Inheritance
XmlReader
Derived
Implements

Examples

The following example code shows how to use the asynchronous API to parse XML.

async Task TestReader(System.IO.Stream stream)
{
    XmlReaderSettings settings = new XmlReaderSettings();
    settings.Async = true;

    using (XmlReader reader = XmlReader.Create(stream, settings))
    {
        while (await reader.ReadAsync())
        {
            switch (reader.NodeType)
            {
                case XmlNodeType.Element:
                    Console.WriteLine("Start Element {0}", reader.Name);
                    break;
                case XmlNodeType.Text:
                    Console.WriteLine("Text Node: {0}",
                             await reader.GetValueAsync());
                    break;
                case XmlNodeType.EndElement:
                    Console.WriteLine("End Element {0}", reader.Name);
                    break;
                default:
                    Console.WriteLine("Other node {0} with value {1}",
                                    reader.NodeType, reader.Value);
                    break;
            }
        }
    }
}
Public Async Function TestReader(stream As System.IO.Stream) As Task
    Dim settings As New XmlReaderSettings()
    settings.Async = True

    Using reader As XmlReader = XmlReader.Create(stream, settings)
        While (Await reader.ReadAsync())
            Select Case (reader.NodeType)
                Case XmlNodeType.Element
                    Console.WriteLine("Start Element {0}", reader.Name)
                Case XmlNodeType.Text
                    Console.WriteLine("Text Node: {0}",
                             Await reader.GetValueAsync())
                Case XmlNodeType.EndElement
                    Console.WriteLine("End Element {0}", reader.Name)
                Case Else
                    Console.WriteLine("Other node {0} with value {1}",
                                    reader.NodeType, reader.Value)
            End Select
        End While
    End Using
End Function

Remarks

For more information about this API, see Supplemental API remarks for XmlReader.

Constructors

XmlReader()

Initializes a new instance of the XmlReader class.

Properties

AttributeCount

When overridden in a derived class, gets the number of attributes on the current node.

BaseURI

When overridden in a derived class, gets the base URI of the current node.

CanReadBinaryContent

Gets a value indicating whether the XmlReader implements the binary content read methods.

CanReadValueChunk

Gets a value indicating whether the XmlReader implements the ReadValueChunk(Char[], Int32, Int32) method.

CanResolveEntity

Gets a value indicating whether this reader can parse and resolve entities.

Depth

When overridden in a derived class, gets the depth of the current node in the XML document.

EOF

When overridden in a derived class, gets a value indicating whether the reader is positioned at the end of the stream.

HasAttributes

Gets a value indicating whether the current node has any attributes.

HasValue

When overridden in a derived class, gets a value indicating whether the current node can have a Value.

IsDefault

When overridden in a derived class, gets a value indicating whether the current node is an attribute that was generated from the default value defined in the DTD or schema.

IsEmptyElement

When overridden in a derived class, gets a value indicating whether the current node is an empty element (for example, <MyElement/>).

Item[Int32]

When overridden in a derived class, gets the value of the attribute with the specified index.

Item[String, String]

When overridden in a derived class, gets the value of the attribute with the specified LocalName and NamespaceURI.

Item[String]

When overridden in a derived class, gets the value of the attribute with the specified Name.

LocalName

When overridden in a derived class, gets the local name of the current node.

Name

When overridden in a derived class, gets the qualified name of the current node.

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.

NameTable

When overridden in a derived class, gets the XmlNameTable associated with this implementation.

NodeType

When overridden in a derived class, gets the type of the current node.

Prefix

When overridden in a derived class, gets the namespace prefix associated with the current node.

QuoteChar

When overridden in a derived class, gets the quotation mark character used to enclose the value of an attribute node.

ReadState

When overridden in a derived class, gets the state of the reader.

SchemaInfo

Gets the schema information that has been assigned to the current node as a result of schema validation.

Settings

Gets the XmlReaderSettings object used to create this XmlReader instance.

Value

When overridden in a derived class, gets the text value of the current node.

ValueType

Gets The Common Language Runtime (CLR) type for the current node.

XmlLang

When overridden in a derived class, gets the current xml:lang scope.

XmlSpace

When overridden in a derived class, gets the current xml:space scope.

Methods

Close()

When overridden in a derived class, changes the ReadState to Closed.

Create(Stream, XmlReaderSettings, String)

Creates a new XmlReader instance using the specified stream, base URI, and settings.

Create(Stream, XmlReaderSettings, XmlParserContext)

Creates a new XmlReader instance using the specified stream, settings, and context information for parsing.

Create(Stream, XmlReaderSettings)

Creates a new XmlReader instance with the specified stream and settings.

Create(Stream)

Creates a new XmlReader instance using the specified stream with default settings.

Create(String, XmlReaderSettings, XmlParserContext)

Creates a new XmlReader instance by using the specified URI, settings, and context information for parsing.

Create(String, XmlReaderSettings)

Creates a new XmlReader instance by using the specified URI and settings.

Create(String)

Creates a new XmlReader instance with specified URI.

Create(TextReader, XmlReaderSettings, String)

Creates a new XmlReader instance by using the specified text reader, settings, and base URI.

Create(TextReader, XmlReaderSettings, XmlParserContext)

Creates a new XmlReader instance by using the specified text reader, settings, and context information for parsing.

Create(TextReader, XmlReaderSettings)

Creates a new XmlReader instance by using the specified text reader and settings.

Create(TextReader)

Creates a new XmlReader instance by using the specified text reader.

Create(XmlReader, XmlReaderSettings)

Creates a new XmlReader instance by using the specified XML reader and settings.

Dispose()

Releases all resources used by the current instance of the XmlReader class.

Dispose(Boolean)

Releases the unmanaged resources used by the XmlReader and optionally releases the managed resources.

Equals(Object)

Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetAttribute(Int32)

When overridden in a derived class, gets the value of the attribute with the specified index.

GetAttribute(String, String)

When overridden in a derived class, gets the value of the attribute with the specified LocalName and NamespaceURI.

GetAttribute(String)

When overridden in a derived class, gets the value of the attribute with the specified Name.

GetHashCode()

Serves as the default hash function.

(Inherited from Object)
GetType()

Gets the Type of the current instance.

(Inherited from Object)
GetValueAsync()

Asynchronously gets the value of the current node.

IsName(String)

Returns a value indicating whether the string argument is a valid XML name.

IsNameToken(String)

Returns a value indicating whether or not the string argument is a valid XML name token.

IsStartElement()

Calls MoveToContent() and tests if the current content node is a start tag or empty element tag.

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.

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.

LookupNamespace(String)

When overridden in a derived class, resolves a namespace prefix in the current element's scope.

MemberwiseClone()

Creates a shallow copy of the current Object.

(Inherited from Object)
MoveToAttribute(Int32)

When overridden in a derived class, moves to the attribute with the specified index.

MoveToAttribute(String, String)

When overridden in a derived class, moves to the attribute with the specified LocalName and NamespaceURI.

MoveToAttribute(String)

When overridden in a derived class, moves to the attribute with the specified Name.

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.

MoveToContentAsync()

Asynchronously checks whether the current node is a content node. If the node is not a content node, the reader skips ahead to the next content node or end of file.

MoveToElement()

When overridden in a derived class, moves to the element that contains the current attribute node.

MoveToFirstAttribute()

When overridden in a derived class, moves to the first attribute.

MoveToNextAttribute()

When overridden in a derived class, moves to the next attribute.

Read()

When overridden in a derived class, reads the next node from the stream.

ReadAsync()

Asynchronously reads the next node from the stream.

ReadAttributeValue()

When overridden in a derived class, parses the attribute value into one or more Text, EntityReference, or EndEntity nodes.

ReadContentAs(Type, IXmlNamespaceResolver)

Reads the content as an object of the type specified.

ReadContentAsAsync(Type, IXmlNamespaceResolver)

Asynchronously reads the content as an object of the type specified.

ReadContentAsBase64(Byte[], Int32, Int32)

Reads the content and returns the Base64 decoded binary bytes.

ReadContentAsBase64Async(Byte[], Int32, Int32)

Asynchronously reads the content and returns the Base64 decoded binary bytes.

ReadContentAsBinHex(Byte[], Int32, Int32)

Reads the content and returns the BinHex decoded binary bytes.

ReadContentAsBinHexAsync(Byte[], Int32, Int32)

Asynchronously reads the content and returns the BinHex decoded binary bytes.

ReadContentAsBoolean()

Reads the text content at the current position as a Boolean.

ReadContentAsDateTime()

Reads the text content at the current position as a DateTime object.

ReadContentAsDateTimeOffset()

Reads the text content at the current position as a DateTimeOffset object.

ReadContentAsDecimal()

Reads the text content at the current position as a Decimal object.

ReadContentAsDouble()

Reads the text content at the current position as a double-precision floating-point number.

ReadContentAsFloat()

Reads the text content at the current position as a single-precision floating point number.

ReadContentAsInt()

Reads the text content at the current position as a 32-bit signed integer.

ReadContentAsLong()

Reads the text content at the current position as a 64-bit signed integer.

ReadContentAsObject()

Reads the text content at the current position as an Object.

ReadContentAsObjectAsync()

Asynchronously reads the text content at the current position as an Object.

ReadContentAsString()

Reads the text content at the current position as a String object.

ReadContentAsStringAsync()

Asynchronously reads the text content at the current position as a String object.

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.

ReadElementContentAs(Type, IXmlNamespaceResolver)

Reads the element content as the requested type.

ReadElementContentAsAsync(Type, IXmlNamespaceResolver)

Asynchronously reads the element content as the requested type.

ReadElementContentAsBase64(Byte[], Int32, Int32)

Reads the element and decodes the Base64 content.

ReadElementContentAsBase64Async(Byte[], Int32, Int32)

Asynchronously reads the element and decodes the Base64 content.

ReadElementContentAsBinHex(Byte[], Int32, Int32)

Reads the element and decodes the BinHex content.

ReadElementContentAsBinHexAsync(Byte[], Int32, Int32)

Asynchronously reads the element and decodes the BinHex content.

ReadElementContentAsBoolean()

Reads the current element and returns the contents as a Boolean object.

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.

ReadElementContentAsDateTime()

Reads the current element and returns the contents as a DateTime object.

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.

ReadElementContentAsDecimal()

Reads the current element and returns the contents as a Decimal object.

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.

ReadElementContentAsDouble()

Reads the current element and returns the contents as a double-precision floating-point number.

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.

ReadElementContentAsFloat()

Reads the current element and returns the contents as single-precision floating-point number.

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.

ReadElementContentAsInt()

Reads the current element and returns the contents as a 32-bit signed integer.

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.

ReadElementContentAsLong()

Reads the current element and returns the contents as a 64-bit signed integer.

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.

ReadElementContentAsObject()

Reads the current element and returns the contents as an Object.

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.

ReadElementContentAsObjectAsync()

Asynchronously reads the current element and returns the contents as an Object.

ReadElementContentAsString()

Reads the current element and returns the contents as a String object.

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.

ReadElementContentAsStringAsync()

Asynchronously reads the current element and returns the contents as a String object.

ReadElementString()

Reads a text-only element. However, we recommend that you use the ReadElementContentAsString() method instead, because it provides a more straightforward way to handle this operation.

ReadElementString(String, String)

Checks that the LocalName and NamespaceURI properties of the element found matches the given strings before reading a text-only element. However, we recommend that you use the ReadElementContentAsString(String, String) method instead, because it provides a more straightforward way to handle this operation.

ReadElementString(String)

Checks that the Name property of the element found matches the given string before reading a text-only element. However, we recommend that you use the ReadElementContentAsString() method instead, because it provides a more straightforward way to handle this operation.

ReadEndElement()

Checks that the current content node is an end tag and advances the reader to the next node.

ReadInnerXml()

When overridden in a derived class, reads all the content, including markup, as a string.

ReadInnerXmlAsync()

Asynchronously reads all the content, including markup, as a string.

ReadOuterXml()

When overridden in a derived class, reads the content, including markup, representing this node and all its children.

ReadOuterXmlAsync()

Asynchronously reads the content, including markup, representing this node and all its children.

ReadStartElement()

Checks that the current node is an element and advances the reader to the next node.

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.

ReadStartElement(String)

Checks that the current content node is an element with the given Name and advances the reader to the next node.

ReadString()

When overridden in a derived class, reads the contents of an element or text node as a string. However, we recommend that you use the ReadElementContentAsString method instead, because it provides a more straightforward way to handle this operation.

ReadSubtree()

Returns a new XmlReader instance that can be used to read the current node, and all its descendants.

ReadToDescendant(String, String)

Advances the XmlReader to the next descendant element with the specified local name and namespace URI.

ReadToDescendant(String)

Advances the XmlReader to the next descendant element with the specified qualified name.

ReadToFollowing(String, String)

Reads until an element with the specified local name and namespace URI is found.

ReadToFollowing(String)

Reads until an element with the specified qualified name is found.

ReadToNextSibling(String, String)

Advances the XmlReader to the next sibling element with the specified local name and namespace URI.

ReadToNextSibling(String)

Advances the XmlReader to the next sibling element with the specified qualified name.

ReadValueChunk(Char[], Int32, Int32)

Reads large streams of text embedded in an XML document.

ReadValueChunkAsync(Char[], Int32, Int32)

Asynchronously reads large streams of text embedded in an XML document.

ResolveEntity()

When overridden in a derived class, resolves the entity reference for EntityReference nodes.

Skip()

Skips the children of the current node.

SkipAsync()

Asynchronously skips the children of the current node.

ToString()

Returns a string that represents the current object.

(Inherited from Object)

Explicit Interface Implementations

IDisposable.Dispose()

For a description of this member, see Dispose().

Applies to

See also