1 out of 2 rated this helpful - Rate this topic

XmlReader Class

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

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
public abstract class XmlReader : IDisposable

The XmlReader type exposes the following members.

  NameDescription
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsXmlReaderInitializes a new instance of the XmlReader class.
Top
  NameDescription
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsAttributeCountWhen overridden in a derived class, gets the number of attributes on the current node.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsBaseURIWhen overridden in a derived class, gets the base URI of the current node.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCanReadBinaryContentGets a value indicating whether the XmlReader implements the binary content read methods.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCanReadValueChunkGets a value indicating whether the XmlReader implements the ReadValueChunk method.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCanResolveEntityGets a value indicating whether this reader can parse and resolve entities.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsDepthWhen overridden in a derived class, gets the depth of the current node in the XML document.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsEOFWhen overridden in a derived class, gets a value indicating whether the reader is positioned at the end of the stream.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsHasAttributesGets a value indicating whether the current node has any attributes.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsHasValueWhen overridden in a derived class, gets a value indicating whether the current node can have a Value.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsDefaultWhen 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.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsEmptyElementWhen overridden in a derived class, gets a value indicating whether the current node is an empty element (for example, <MyElement/>).
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsItem[Int32]When overridden in a derived class, gets the value of the attribute with the specified index.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsItem[String]When overridden in a derived class, gets the value of the attribute with the specified Name.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsItem[String, String]When overridden in a derived class, gets the value of the attribute with the specified LocalName and NamespaceURI.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsLocalNameWhen overridden in a derived class, gets the local name of the current node.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsNameWhen overridden in a derived class, gets the qualified name of the current node.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsNamespaceURIWhen 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 propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsNameTableWhen overridden in a derived class, gets the XmlNameTable associated with this implementation.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsNodeTypeWhen overridden in a derived class, gets the type of the current node.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsPrefixWhen overridden in a derived class, gets the namespace prefix associated with the current node.
Public propertySupported by the XNA FrameworkQuoteCharWhen overridden in a derived class, gets the quotation mark character used to enclose the value of an attribute node.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadStateWhen overridden in a derived class, gets the state of the reader.
Public propertySupported by the XNA FrameworkSchemaInfoGets the schema information that has been assigned to the current node as a result of schema validation.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSettingsGets the XmlReaderSettings object used to create this XmlReader instance.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsValueWhen overridden in a derived class, gets the text value of the current node.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsValueTypeGets The Common Language Runtime (CLR) type for the current node.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsXmlLangWhen overridden in a derived class, gets the current xml:lang scope.
Public propertySupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsXmlSpaceWhen overridden in a derived class, gets the current xml:space scope.
Top
  NameDescription
Public methodSupported by the XNA FrameworkCloseWhen overridden in a derived class, changes the ReadState to Closed.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreate(Stream)Creates a new XmlReader instance using the specified stream.
Public methodStatic memberSupported by the XNA FrameworkSupported in .NET for Windows Store appsCreate(String)Creates a new XmlReader instance with specified URI.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreate(TextReader)Creates a new XmlReader instance with the specified TextReader.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreate(Stream, XmlReaderSettings)Creates a new XmlReader instance with the specified stream and XmlReaderSettings object.
Public methodStatic memberSupported by the XNA FrameworkSupported in .NET for Windows Store appsCreate(String, XmlReaderSettings)Creates a new instance with the specified URI and XmlReaderSettings.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreate(TextReader, XmlReaderSettings)Creates a new XmlReader instance using the specified TextReader and XmlReaderSettings objects.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreate(XmlReader, XmlReaderSettings)Creates a new XmlReader instance with the specified XmlReader and XmlReaderSettings objects.
Public methodStatic memberSupported by the XNA FrameworkCreate(Stream, XmlReaderSettings, String)Creates a new XmlReader instance using the specified stream, base URI, and XmlReaderSettings object.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreate(Stream, XmlReaderSettings, XmlParserContext)Creates a new XmlReader instance using the specified stream, XmlReaderSettings, and XmlParserContext objects.
Public methodStatic memberSupported by the XNA FrameworkCreate(String, XmlReaderSettings, XmlParserContext)Creates a new XmlReader instance using the specified URI, XmlReaderSettings, and XmlParserContext objects.
Public methodStatic memberSupported by the XNA FrameworkCreate(TextReader, XmlReaderSettings, String)Creates a new XmlReader instance using the specified TextReader, XmlReaderSettings, and base URI.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsCreate(TextReader, XmlReaderSettings, XmlParserContext)Creates a new XmlReader instance using the specified TextReader, XmlReaderSettings, and XmlParserContext objects.
Public methodSupported by Portable Class LibrarySupported in .NET for Windows Store appsDispose()Releases all resources used by the current instance of the XmlReader class.
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsDispose(Boolean)Releases the unmanaged resources used by the XmlReader and optionally releases the managed resources.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetAttribute(Int32)When overridden in a derived class, gets the value of the attribute with the specified index.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetAttribute(String)When overridden in a derived class, gets the value of the attribute with the specified Name.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetAttribute(String, String)When overridden in a derived class, gets the value of the attribute with the specified LocalName and NamespaceURI.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodSupported in .NET for Windows Store appsGetValueAsyncAsynchronously gets the value of the current node.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsNameReturns a value indicating whether the string argument is a valid XML name.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsNameTokenReturns a value indicating whether or not the string argument is a valid XML name token.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsStartElement()Calls MoveToContent and tests if the current content node is a start tag or empty element tag.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsStartElement(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 methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsIsStartElement(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 methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsLookupNamespaceWhen overridden in a derived class, resolves a namespace prefix in the current element's scope.
Protected methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMoveToAttribute(Int32)When overridden in a derived class, moves to the attribute with the specified index.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMoveToAttribute(String)When overridden in a derived class, moves to the attribute with the specified Name.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMoveToAttribute(String, String)When overridden in a derived class, moves to the attribute with the specified LocalName and NamespaceURI.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMoveToContentChecks 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 methodSupported in .NET for Windows Store appsMoveToContentAsyncAsynchronously 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.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMoveToElementWhen overridden in a derived class, moves to the element that contains the current attribute node.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMoveToFirstAttributeWhen overridden in a derived class, moves to the first attribute.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsMoveToNextAttributeWhen overridden in a derived class, moves to the next attribute.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadWhen overridden in a derived class, reads the next node from the stream.
Public methodSupported in .NET for Windows Store appsReadAsyncAsynchronously reads the next node from the stream.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadAttributeValueWhen overridden in a derived class, parses the attribute value into one or more Text, EntityReference, or EndEntity nodes.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadContentAsReads the content as an object of the type specified.
Public methodSupported in .NET for Windows Store appsReadContentAsAsyncAsynchronously reads the content as an object of the type specified.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadContentAsBase64Reads the content and returns the Base64 decoded binary bytes.
Public methodSupported in .NET for Windows Store appsReadContentAsBase64AsyncAsynchronously reads the content and returns the Base64 decoded binary bytes.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadContentAsBinHexReads the content and returns the BinHex decoded binary bytes.
Public methodSupported in .NET for Windows Store appsReadContentAsBinHexAsyncAsynchronously reads the content and returns the BinHex decoded binary bytes.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadContentAsBooleanReads the text content at the current position as a Boolean.
Public methodSupported by the XNA FrameworkReadContentAsDateTimeReads the text content at the current position as a DateTime object.
Public methodSupported in .NET for Windows Store appsReadContentAsDateTimeOffsetReads the text content at the current position as a DateTimeOffset object.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadContentAsDecimalReads the text content at the current position as a Decimal object.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadContentAsDoubleReads the text content at the current position as a double-precision floating-point number.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadContentAsFloatReads the text content at the current position as a single-precision floating point number.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadContentAsIntReads the text content at the current position as a 32-bit signed integer.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadContentAsLongReads the text content at the current position as a 64-bit signed integer.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadContentAsObjectReads the text content at the current position as an Object.
Public methodSupported in .NET for Windows Store appsReadContentAsObjectAsyncAsynchronously reads the text content at the current position as an Object.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadContentAsStringReads the text content at the current position as a String object.
Public methodSupported in .NET for Windows Store appsReadContentAsStringAsyncAsynchronously reads the text content at the current position as a String object.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAs(Type, IXmlNamespaceResolver)Reads the element content as the requested type.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAs(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.
Public methodSupported in .NET for Windows Store appsReadElementContentAsAsyncAsynchronously reads the element content as the requested type.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsBase64Reads the element and decodes the Base64 content.
Public methodSupported in .NET for Windows Store appsReadElementContentAsBase64AsyncAsynchronously reads the element and decodes the Base64 content.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsBinHexReads the element and decodes the BinHex content.
Public methodSupported in .NET for Windows Store appsReadElementContentAsBinHexAsyncAsynchronously reads the element and decodes the BinHex content.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsBoolean()Reads the current element and returns the contents as a Boolean object.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsBoolean(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.
Public methodSupported by the XNA FrameworkReadElementContentAsDateTime()Reads the current element and returns the contents as a DateTime object.
Public methodSupported by the XNA FrameworkReadElementContentAsDateTime(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.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsDecimal()Reads the current element and returns the contents as a Decimal object.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsDecimal(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.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsDouble()Reads the current element and returns the contents as a double-precision floating-point number.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsDouble(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.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsFloat()Reads the current element and returns the contents as single-precision floating-point number.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsFloat(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.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsInt()Reads the current element and returns the contents as a 32-bit signed integer.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsInt(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.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsLong()Reads the current element and returns the contents as a 64-bit signed integer.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsLong(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.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsObject()Reads the current element and returns the contents as an Object.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsObject(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.
Public methodSupported in .NET for Windows Store appsReadElementContentAsObjectAsyncAsynchronously reads the current element and returns the contents as an Object.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsString()Reads the current element and returns the contents as a String object.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadElementContentAsString(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.
Public methodSupported in .NET for Windows Store appsReadElementContentAsStringAsyncAsynchronously reads the current element and returns the contents as a String object.
Public methodSupported by the XNA FrameworkReadElementString()Reads a text-only element.
Public methodSupported by the XNA FrameworkReadElementString(String)Checks that the Name property of the element found matches the given string before reading a text-only element.
Public methodSupported by the XNA FrameworkReadElementString(String, String)Checks that the LocalName and NamespaceURI properties of the element found matches the given strings before reading a text-only element.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadEndElementChecks that the current content node is an end tag and advances the reader to the next node.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadInnerXmlWhen overridden in a derived class, reads all the content, including markup, as a string.
Public methodSupported in .NET for Windows Store appsReadInnerXmlAsyncAsynchronously reads all the content, including markup, as a string.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadOuterXmlWhen overridden in a derived class, reads the content, including markup, representing this node and all its children.
Public methodSupported in .NET for Windows Store appsReadOuterXmlAsyncAsynchronously reads the content, including markup, representing this node and all its children.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadStartElement()Checks that the current node is an element and advances the reader to the next node.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadStartElement(String)Checks that the current content node is an element with the given Name and advances the reader to the next node.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadStartElement(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 methodSupported by the XNA FrameworkReadStringWhen overridden in a derived class, reads the contents of an element or text node as a string.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadSubtreeReturns a new XmlReader instance that can be used to read the current node, and all its descendants.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadToDescendant(String)Advances the XmlReader to the next descendant element with the specified qualified name.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadToDescendant(String, String)Advances the XmlReader to the next descendant element with the specified local name and namespace URI.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadToFollowing(String)Reads until an element with the specified qualified name is found.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadToFollowing(String, String)Reads until an element with the specified local name and namespace URI is found.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadToNextSibling(String)Advances the XmlReader to the next sibling element with the specified qualified name.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadToNextSibling(String, String)Advances the XmlReader to the next sibling element with the specified local name and namespace URI.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsReadValueChunkReads large streams of text embedded in an XML document.
Public methodSupported in .NET for Windows Store appsReadValueChunkAsyncAsynchronously reads large streams of text embedded in an XML document.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsResolveEntityWhen overridden in a derived class, resolves the entity reference for EntityReference nodes.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsSkipSkips the children of the current node.
Public methodSupported in .NET for Windows Store appsSkipAsyncAsynchronously skips the children of the current node.
Public methodSupported by the XNA FrameworkSupported by Portable Class LibrarySupported in .NET for Windows Store appsToStringReturns a string that represents the current object. (Inherited from Object.)
Top
  NameDescription
Explicit interface implemetationPrivate methodSupported by the XNA FrameworkIDisposable.DisposeFor a description of this member, see IDisposable.Dispose.
Top

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.

Important noteImportant

Although the Microsoft .NET Framework includes concrete implementations of the XmlReader class, such as the XmlTextReader, XmlNodeReader, and the XmlValidatingReader classes, in the 2.0 release the recommended practice is to create XmlReader instances using the Create method. For more information, see Creating XML Readers.

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.

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

Not all synchronous methods have an equivalent asynchronous method. The following table shows the equivalent asynchronous usage for synchronous methods.

Synchronous Method

Equivalent Asynchronous method/code

ReadContentAsXXX

Use the ReadContentAsObjectAsync, ReadContentAsStringAsync or ReadContentAsAsync methods instead.

ReadElementContentAsXXX

Use the ReadElementContentAsObjectAsync, ReadElementContentAsStringAsync or ReadElementContentAsAsync methods instead.

ReadStartElement

public static async Task ReadStartElementAsync(this XmlReader reader, string localname, string ns) {
 if (await 
   reader.MoveToContentAsync() != 
   XmlNodeType.Element) {
 throw new 
InvalidOperationException(
reader.NodeType.ToString() + " is an invalid XmlNodeType");
   }
 if (reader.LocalName == 
     localname && 
     reader.NamespaceURI == ns) {
 await reader.ReadAsync();
   }
 else {
 throw new InvalidOperationException("localName or namespace doesn’t match");
    }
}

ReadEndElement

Extension function:

public static async Task ReadEndElementAsync(this XmlReader reader) {
if (await reader.MoveToContentAsync() != XmlNodeType.EndElement) {
    throw new InvalidOperationException();
   }
 await reader.ReadAsync();
}

ReadToNextSibling

public static async Task<bool> ReadToNextSiblingAsync(this XmlReader reader, string localName, string namespaceURI) {
 if (localName == null || 
    localName.Length == 0) {
 throw new ArgumentException ("localName is empty or null");
   }
 if (namespaceURI == null) {
 throw new ArgumentNullException("namespaceURI");
   }

// atomize local name and namespace
   localName = 
    reader.NameTable.Add(localName);
   namespaceURI = 
   reader.NameTable.Add(namespaceURI);

// find the next sibling
 XmlNodeType nt;
 do {
 await reader.SkipAsync();
 if (reader.ReadState !=
 ReadState.Interactive)
 break;
      nt = reader.NodeType;
 if (nt == XmlNodeType.Element &&
      ((object)localName == 
      (object)reader.LocalName) && 
      ((object)namespaceURI == 
      (object)reader.NamespaceURI)) {
 return true;
       }
   }while(nt != XmlNodeType.EndElement 

   && !reader.EOF);
 return false;
}

ReadToFollowing

public static async Task<bool> ReadToFollowingAsync(this XmlReader reader, string localName, string namespaceURI) 
{
 if (localName == null || 
     localName.Length == 0) {
 throw new 
     ArgumentException(
     "localName is empty or null");
   }
 if (namespaceURI == null) {
 throw new 
      ArgumentNullException(
     "namespaceURI");
}

// atomize local name and namespace
   localName = 
    reader.NameTable.Add(localName);
   namespaceURI = 
   reader.NameTable.Add(namespaceURI);

// find element with that name
 while (await reader.ReadAsync()) {
 if (reader.NodeType == XmlNodeType.Element && ((object)localName == (object)reader.LocalName) && ((object)namespaceURI == (object)reader.NamespaceURI)) {
 return true;
      }
   }
 return false;
}

ReadToDescendant

public static async Task<bool> ReadToDescendantAsync(this XmlReader reader, string localName, string namespaceURI) {
 if (localName == null || localName.Length == 0) {
 throw new ArgumentException("localName is empty or null");
   }
 if (namespaceURI == null) {
 throw new ArgumentNullException("namespaceURI");
   }
 // save the element or root depth
 int parentDepth = reader.Depth;
 if (reader.NodeType != XmlNodeType.Element) {
 // adjust the depth if we are on root node
if (reader.ReadState == ReadState.Initial) {
    parentDepth--;
   }
else {
     return false;
       }
   }
else if (reader.IsEmptyElement) {
   return false;
}

// atomize local name and namespace
localName = reader.NameTable.Add(localName);
namespaceURI = reader.NameTable.Add(namespaceURI);

// find the descendant
while (await reader.ReadAsync() && reader.Depth > parentDepth) {
if (reader.NodeType == XmlNodeType.Element && ((object)localName == (object)reader.LocalName) && ((object)namespaceURI == (object)reader.NamespaceURI)) {
 return true;
}
}
return false;
}

GetAttribute, MoveToAttribute, MoveToFirstAttribute, MoveToNextAttribute, MovetoElement, ReadAttributeValue, ResolveEntity, and ReadSubtree

These methods can be used with Asynchronous methods calls.

Security Considerations

The following items are things to consider when working with the XmlReader class.

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

  • Do not enable DTD processing if you are concerned about denial of service issues or if you are dealing with untrusted sources. DTD processing is disabled by default for XmlReader objects created by the Create method.

    If you have DTD processing enabled, you can use the XmlSecureResolver to restrict the resources that the XmlReader 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 schema 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 XmlReader, create a custom IStream implementation and supply it the XmlReader.

  • 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.

  • When reading an XML document with a large number of unique local names, namespaces, or prefixes, a problem can occur. If you are using a class that derives from XmlReader, and you call either the LocalName, Prefix, or NamespaceURI property for each item, the returned string is added to a NameTable. The collection held by the NameTable never decreases in size, creating a virtual "memory leak" of the string handles. One mitigation for this is to derive from the NameTable class and enforce a maximum size quota. (There is no way to prevent the use of a NameTable, or to switch the NameTable when it is full). Another mitigation is to avoid using the properties mentioned and instead use the MoveToAttribute method with the IsStartElement method where possible; those methods do not return strings and thus avoid the problem of overfilling the NameTable collection.

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

async Task TestReader(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;
         }
      }
   }
}

.NET Framework

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

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

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)
© 2013 Microsoft. All rights reserved.