Early Preview
This is currently very much a preview. Please feel free to try things out,
but don't be upset if anything is not yet working. Feedback is welcome over on our
GitHub Dicussions page.
class System.​Xml.​XmlReader
Assembly: System.Xml.ReaderWriter
Inheritance: object → XmlReader
Implemented Interfaces
Represents a reader that provides fast, noncached, forward-only access to XML data.
Properties
public
int
AttributeCount
When overridden in a derived class, gets the number of attributes on the current node.
public
string
BaseURI
When overridden in a derived class, gets the base URI of the current node.
public
bool
CanReadBinaryContent
Gets a value indicating whether the <see cref="T:System.Xml.XmlReader" /> implements the binary content read methods.
public
bool
CanReadValueChunk
Gets a value indicating whether the <see cref="T:System.Xml.XmlReader" /> implements the <see cref="M:System.Xml.XmlReader.ReadValueChunk(System.Char[],System.Int32,System.Int32)" /> method.
public
bool
CanResolveEntity
Gets a value indicating whether this reader can parse and resolve entities.
public
int
Depth
When overridden in a derived class, gets the depth of the current node in the XML document.
public
bool
EOF
When overridden in a derived class, gets a value indicating whether the reader is positioned at the end of the stream.
public
bool
HasAttributes
Gets a value indicating whether the current node has any attributes.
public
bool
HasValue
When overridden in a derived class, gets a value indicating whether the current node can have a <see cref="P:System.Xml.XmlReader.Value" /> .
public
bool
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.
public
bool
IsEmptyElement
When overridden in a derived class, gets a value indicating whether the current node is an empty element (for example, <c><MyElement/></c> ).
public
string
Item
public
string
Item
public
string
Item
public
string
LocalName
When overridden in a derived class, gets the local name of the current node.
public
string
Name
When overridden in a derived class, gets the qualified name of the current node.
public
string
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
XmlNameTable
NameTable
When overridden in a derived class, gets the <see cref="T:System.Xml.XmlNameTable" /> associated with this implementation.
public
XmlNodeType
NodeType
When overridden in a derived class, gets the type of the current node.
public
string
Prefix
When overridden in a derived class, gets the namespace prefix associated with the current node.
public
char
QuoteChar
When overridden in a derived class, gets the quotation mark character used to enclose the value of an attribute node.
public
ReadState
ReadState
When overridden in a derived class, gets the state of the reader.
public
IXmlSchemaInfo
SchemaInfo
Gets the schema information that has been assigned to the current node as a result of schema validation.
public
XmlReaderSettings
Settings
Gets the <see cref="T:System.Xml.XmlReaderSettings" /> object used to create this <see cref="T:System.Xml.XmlReader" /> instance.
public
string
Value
When overridden in a derived class, gets the text value of the current node.
public
Type
ValueType
Gets The Common Language Runtime (CLR) type for the current node.
public
string
XmlLang
When overridden in a derived class, gets the current <see langword="xml:lang" /> scope.
public
XmlSpace
XmlSpace
When overridden in a derived class, gets the current <see langword="xml:space" /> scope.
Methods
public
void
Close​()
When overridden in a derived class, changes the <see cref="P:System.Xml.XmlReader.ReadState" /> to <see cref="F:System.Xml.ReadState.Closed" /> .
public static
XmlReader
Create​(IO.​Stream input)
Creates a new <see cref="T:System.Xml.XmlReader" /> instance using the specified stream with default settings.
Returns An object that is used to read the XML data in the stream.
input
The stream that contains the XML data.
The <see cref="T:System.Xml.XmlReader" /> scans the first bytes of the stream looking for a byte order mark or other sign of encoding. When encoding is determined, the encoding is used to continue reading the stream, and processing continues parsing the input as a stream of (Unicode) characters.
public static
XmlReader
Create​(IO.​Stream input,
XmlReaderSettings? settings)
Creates a new <see cref="T:System.Xml.XmlReader" /> instance with the specified stream and settings.
Returns An object that is used to read the XML data in the stream.
input
The stream that contains the XML data.
The <see cref="T:System.Xml.XmlReader" /> scans the first bytes of the stream looking for a byte order mark or other sign of encoding. When encoding is determined, the encoding is used to continue reading the stream, and processing continues parsing the input as a stream of (Unicode) characters.
settings
The settings for the new <see cref="T:System.Xml.XmlReader" /> instance. This value can be <see langword="null" /> .
public static
XmlReader
Create​(IO.​Stream input,
XmlReaderSettings? settings,
string baseUri)
Creates a new <see cref="T:System.Xml.XmlReader" /> instance using the specified stream, base URI, and settings.
Returns An object that is used to read the XML data in the stream.
input
The stream that contains the XML data.
The <see cref="T:System.Xml.XmlReader" /> scans the first bytes of the stream looking for a byte order mark or other sign of encoding. When encoding is determined, the encoding is used to continue reading the stream, and processing continues parsing the input as a stream of (Unicode) characters.
settings
The settings for the new <see cref="T:System.Xml.XmlReader" /> instance. This value can be <see langword="null" /> .
baseUri
The base URI for the entity or document being read. This value can be <see langword="null" /> .
Security Note The base URI is used to resolve the relative URI of the XML document. Do not use a base URI from an untrusted source.
public static
XmlReader
Create​(IO.​Stream input,
XmlReaderSettings? settings,
XmlParserContext? inputContext)
Creates a new <see cref="T:System.Xml.XmlReader" /> instance using the specified stream, settings, and context information for parsing.
Returns An object that is used to read the XML data in the stream.
input
The stream that contains the XML data.
The <see cref="T:System.Xml.XmlReader" /> scans the first bytes of the stream looking for a byte order mark or other sign of encoding. When encoding is determined, the encoding is used to continue reading the stream, and processing continues parsing the input as a stream of (Unicode) characters.
settings
The settings for the new <see cref="T:System.Xml.XmlReader" /> instance. This value can be <see langword="null" /> .
inputContext
The context information required to parse the XML fragment. The context information can include the <see cref="T:System.Xml.XmlNameTable" /> to use, encoding, namespace scope, the current <c>xml:lang</c> and <c>xml:space</c> scope, base URI, and document type definition.
This value can be <see langword="null" /> .
public static
XmlReader
Create​(IO.​TextReader input)
Creates a new <see cref="T:System.Xml.XmlReader" /> instance by using the specified text reader.
Returns An object that is used to read the XML data in the stream.
input
The text reader from which to read the XML data. A text reader returns a stream of Unicode characters, so the encoding specified in the XML declaration is not used by the XML reader to decode the data stream.
public static
XmlReader
Create​(IO.​TextReader input,
XmlReaderSettings? settings)
Creates a new <see cref="T:System.Xml.XmlReader" /> instance by using the specified text reader and settings.
Returns An object that is used to read the XML data in the stream.
input
The text reader from which to read the XML data. A text reader returns a stream of Unicode characters, so the encoding specified in the XML declaration isn't used by the XML reader to decode the data stream.
settings
The settings for the new <see cref="T:System.Xml.XmlReader" /> . This value can be <see langword="null" /> .
public static
XmlReader
Create​(IO.​TextReader input,
XmlReaderSettings? settings,
string baseUri)
Creates a new <see cref="T:System.Xml.XmlReader" /> instance by using the specified text reader, settings, and base URI.
Returns An object that is used to read the XML data in the stream.
input
The text reader from which to read the XML data. A text reader returns a stream of Unicode characters, so the encoding specified in the XML declaration isn't used by the <see cref="T:System.Xml.XmlReader" /> to decode the data stream.
settings
The settings for the new <see cref="T:System.Xml.XmlReader" /> instance. This value can be <see langword="null" /> .
baseUri
The base URI for the entity or document being read. This value can be <see langword="null" /> .
Security Note The base URI is used to resolve the relative URI of the XML document. Do not use a base URI from an untrusted source.
public static
XmlReader
Create​(IO.​TextReader input,
XmlReaderSettings? settings,
XmlParserContext? inputContext)
Creates a new <see cref="T:System.Xml.XmlReader" /> instance by using the specified text reader, settings, and context information for parsing.
Returns An object that is used to read the XML data in the stream.
input
The text reader from which to read the XML data. A text reader returns a stream of Unicode characters, so the encoding specified in the XML declaration isn't used by the XML reader to decode the data stream.
settings
The settings for the new <see cref="T:System.Xml.XmlReader" /> instance. This value can be <see langword="null" /> .
inputContext
The context information required to parse the XML fragment. The context information can include the <see cref="T:System.Xml.XmlNameTable" /> to use, encoding, namespace scope, the current <c>xml:lang</c> and <c>xml:space</c> scope, base URI, and document type definition.
This value can be <see langword="null" /> .
public static
XmlReader
Create​(string inputUri)
Creates a new <see cref="T:System.Xml.XmlReader" /> instance with specified URI.
Returns An object that is used to read the XML data in the stream.
inputUri
The URI for the file that contains the XML data. The <see cref="T:System.Xml.XmlUrlResolver" /> class is used to convert the path to a canonical data representation.
public static
XmlReader
Create​(string inputUri,
XmlReaderSettings? settings)
Creates a new <see cref="T:System.Xml.XmlReader" /> instance by using the specified URI and settings.
Returns An object that is used to read the XML data in the stream.
inputUri
The URI for the file containing the XML data. The <see cref="T:System.Xml.XmlResolver" /> object on the <see cref="T:System.Xml.XmlReaderSettings" /> object is used to convert the path to a canonical data representation. If <see cref="P:System.Xml.XmlReaderSettings.XmlResolver" /> is <see langword="null" /> , a new <see cref="T:System.Xml.XmlUrlResolver" /> object is used.
settings
The settings for the new <see cref="T:System.Xml.XmlReader" /> instance. This value can be <see langword="null" /> .
public static
XmlReader
Create​(string inputUri,
XmlReaderSettings? settings,
XmlParserContext? inputContext)
Creates a new <see cref="T:System.Xml.XmlReader" /> instance by using the specified URI, settings, and context information for parsing.
Returns An object that is used to read the XML data in the stream.
inputUri
The URI for the file containing the XML data. The <see cref="T:System.Xml.XmlResolver" /> object on the <see cref="T:System.Xml.XmlReaderSettings" /> object is used to convert the path to a canonical data representation. If <see cref="P:System.Xml.XmlReaderSettings.XmlResolver" /> is <see langword="null" /> , a new <see cref="T:System.Xml.XmlUrlResolver" /> object is used.
settings
The settings for the new <see cref="T:System.Xml.XmlReader" /> instance. This value can be <see langword="null" /> .
inputContext
The context information required to parse the XML fragment. The context information can include the <see cref="T:System.Xml.XmlNameTable" /> to use, encoding, namespace scope, the current <c>xml:lang</c> and <c>xml:space</c> scope, base URI, and document type definition.
This value can be <see langword="null" /> .
public static
XmlReader
Create​(XmlReader reader,
XmlReaderSettings? settings)
Creates a new <see cref="T:System.Xml.XmlReader" /> instance by using the specified XML reader and settings.
Returns An object that is wrapped around the specified <see cref="T:System.Xml.XmlReader" /> object.
reader
The object that you want to use as the underlying XML reader.
settings
The settings for the new <see cref="T:System.Xml.XmlReader" /> instance.
The conformance level of the <see cref="T:System.Xml.XmlReaderSettings" /> object must either match the conformance level of the underlying reader, or it must be set to <see cref="F:System.Xml.ConformanceLevel.Auto" /> .
public
void
Dispose​()
Releases all resources used by the current instance of the <see cref="T:System.Xml.XmlReader" /> class.
protected
void
Dispose​(bool disposing)
Releases the unmanaged resources used by the <see cref="T:System.Xml.XmlReader" /> and optionally releases the managed resources.
disposing
<see langword="true" /> to release both managed and unmanaged resources; <see langword="false" /> to release only unmanaged resources.
public
string
GetAttribute​(int i)
When overridden in a derived class, gets the value of the attribute with the specified index.
Returns The value of the specified attribute. This method does not move the reader.
i
The index of the attribute. The index is zero-based. (The first attribute has index 0.)
public
string
GetAttribute​(string name)
When overridden in a derived class, gets the value of the attribute with the specified <see cref="P:System.Xml.XmlReader.Name" /> .
Returns The value of the specified attribute. If the attribute is not found or the value is <see langword="String.Empty" /> , <see langword="null" /> is returned.
name
The qualified name of the attribute.
public
string
GetAttribute​(string name,
string namespaceURI)
When overridden in a derived class, gets the value of the attribute with the specified <see cref="P:System.Xml.XmlReader.LocalName" /> and <see cref="P:System.Xml.XmlReader.NamespaceURI" /> .
Returns The value of the specified attribute. If the attribute is not found or the value is <see langword="String.Empty" /> , <see langword="null" /> is returned. This method does not move the reader.
name
The local name of the attribute.
namespaceURI
The namespace URI of the attribute.
public
Threading.​Tasks.​Task<​string>
GetValueAsync​()
Asynchronously gets the value of the current node.
Returns The value of the current node.
public static
bool
IsName​(string str)
Returns a value indicating whether the string argument is a valid XML name.
Returns <see langword="true" /> if the name is valid; otherwise, <see langword="false" /> .
str
The name to validate.
public static
bool
IsNameToken​(string str)
Returns a value indicating whether or not the string argument is a valid XML name token.
Returns <see langword="true" /> if it is a valid name token; otherwise <see langword="false" /> .
str
The name token to validate.
public
bool
IsStartElement​()
Calls <see cref="M:System.Xml.XmlReader.MoveToContent" /> and tests if the current content node is a start tag or empty element tag.
Returns <see langword="true" /> if <see cref="M:System.Xml.XmlReader.MoveToContent" /> finds a start tag or empty element tag; <see langword="false" /> if a node type other than <see langword="XmlNodeType.Element" /> was found.
public
bool
IsStartElement​(string name)
Calls <see cref="M:System.Xml.XmlReader.MoveToContent" /> and tests if the current content node is a start tag or empty element tag and if the <see cref="P:System.Xml.XmlReader.Name" /> property of the element found matches the given argument.
Returns <see langword="true" /> if the resulting node is an element and the <see langword="Name" /> property matches the specified string. <see langword="false" /> if a node type other than <see langword="XmlNodeType.Element" /> was found or if the element <see langword="Name" /> property does not match the specified string.
name
The string matched against the <see langword="Name" /> property of the element found.
public
bool
IsStartElement​(string localname,
string ns)
Calls <see cref="M:System.Xml.XmlReader.MoveToContent" /> and tests if the current content node is a start tag or empty element tag and if the <see cref="P:System.Xml.XmlReader.LocalName" /> and <see cref="P:System.Xml.XmlReader.NamespaceURI" /> properties of the element found match the given strings.
Returns <see langword="true" /> if the resulting node is an element. <see langword="false" /> if a node type other than <see langword="XmlNodeType.Element" /> was found or if the <see langword="LocalName" /> and <see langword="NamespaceURI" /> properties of the element do not match the specified strings.
localname
The string to match against the <see langword="LocalName" /> property of the element found.
ns
The string to match against the <see langword="NamespaceURI" /> property of the element found.
public
string
LookupNamespace​(string prefix)
When overridden in a derived class, resolves a namespace prefix in the current element's scope.
Returns The namespace URI to which the prefix maps or <see langword="null" /> if no matching prefix is found.
prefix
The prefix whose namespace URI you want to resolve. To match the default namespace, pass an empty string.
public
void
MoveToAttribute​(int i)
When overridden in a derived class, moves to the attribute with the specified index.
i
The index of the attribute.
public
bool
MoveToAttribute​(string name)
When overridden in a derived class, moves to the attribute with the specified <see cref="P:System.Xml.XmlReader.Name" /> .
Returns <see langword="true" /> if the attribute is found; otherwise, <see langword="false" /> . If <see langword="false" /> , the reader's position does not change.
name
The qualified name of the attribute.
public
bool
MoveToAttribute​(string name,
string ns)
When overridden in a derived class, moves to the attribute with the specified <see cref="P:System.Xml.XmlReader.LocalName" /> and <see cref="P:System.Xml.XmlReader.NamespaceURI" /> .
Returns <see langword="true" /> if the attribute is found; otherwise, <see langword="false" /> . If <see langword="false" /> , the reader's position does not change.
name
The local name of the attribute.
ns
The namespace URI of the attribute.
public
XmlNodeType
MoveToContent​()
Checks whether the current node is a content (non-white space text, <see langword="CDATA" /> , <see langword="Element" /> , <see langword="EndElement" /> , <see langword="EntityReference" /> , or <see langword="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: <see langword="ProcessingInstruction" /> , <see langword="DocumentType" /> , <see langword="Comment" /> , <see langword="Whitespace" /> , or <see langword="SignificantWhitespace" /> .
Returns The <see cref="P:System.Xml.XmlReader.NodeType" /> of the current node found by the method or <see langword="XmlNodeType.None" /> if the reader has reached the end of the input stream.
public
Threading.​Tasks.​Task<​XmlNodeType>
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.
Returns The <see cref="P:System.Xml.XmlReader.NodeType" /> of the current node found by the method or <see langword="XmlNodeType.None" /> if the reader has reached the end of the input stream.
public
bool
MoveToElement​()
When overridden in a derived class, moves to the element that contains the current attribute node.
Returns <see langword="true" /> if the reader is positioned on an attribute (the reader moves to the element that owns the attribute); <see langword="false" /> if the reader is not positioned on an attribute (the position of the reader does not change).
public
bool
MoveToFirstAttribute​()
When overridden in a derived class, moves to the first attribute.
Returns <see langword="true" /> if an attribute exists (the reader moves to the first attribute); otherwise, <see langword="false" /> (the position of the reader does not change).
public
bool
MoveToNextAttribute​()
When overridden in a derived class, moves to the next attribute.
Returns <see langword="true" /> if there is a next attribute; <see langword="false" /> if there are no more attributes.
public
bool
Read​()
When overridden in a derived class, reads the next node from the stream.
Returns <see langword="true" /> if the next node was read successfully; otherwise, <see langword="false" /> .
public
Threading.​Tasks.​Task<​bool>
ReadAsync​()
Asynchronously reads the next node from the stream.
Returns <see langword="true" /> if the next node was read successfully; <see langword="false" /> if there are no more nodes to read.
public
bool
ReadAttributeValue​()
When overridden in a derived class, parses the attribute value into one or more <see langword="Text" /> , <see langword="EntityReference" /> , or <see langword="EndEntity" /> nodes.
Returns <see langword="true" /> if there are nodes to return.
<see langword="false" /> if the reader is not positioned on an attribute node when the initial call is made or if all the attribute values have been read.
An empty attribute, such as, <c>misc=""</c> , returns <see langword="true" /> with a single node with a value of <see langword="String.Empty" /> .
public
object
ReadContentAs​(Type returnType,
IXmlNamespaceResolver? namespaceResolver)
Reads the content as an object of the type specified.
Returns The concatenated text content or attribute value converted to the requested type.
returnType
The type of the value to be returned.
Note With the release of the .NET Framework 3.5, the value of the <paramref name="returnType" /> parameter can now be the <see cref="T:System.DateTimeOffset" /> type.
namespaceResolver
An <see cref="T:System.Xml.IXmlNamespaceResolver" /> object that is used to resolve any namespace prefixes related to type conversion. For example, this can be used when converting an <see cref="T:System.Xml.XmlQualifiedName" /> object to an <c>xs:string</c> .
This value can be <see langword="null" /> .
public
Threading.​Tasks.​Task<​object>
ReadContentAsAsync​(Type returnType,
IXmlNamespaceResolver? namespaceResolver)
Asynchronously reads the content as an object of the type specified.
Returns The concatenated text content or attribute value converted to the requested type.
returnType
The type of the value to be returned.
namespaceResolver
An <see cref="T:System.Xml.IXmlNamespaceResolver" /> object that is used to resolve any namespace prefixes related to type conversion.
public
int
ReadContentAsBase64​(byte[] buffer,
int index,
int count)
Reads the content and returns the Base64 decoded binary bytes.
Returns The number of bytes written to the buffer.
buffer
The buffer into which to copy the resulting text. This value cannot be <see langword="null" /> .
index
The offset into the buffer where to start copying the result.
count
The maximum number of bytes to copy into the buffer. The actual number of bytes copied is returned from this method.
public
Threading.​Tasks.​Task<​int>
ReadContentAsBase64Async​(byte[] buffer,
int index,
int count)
Asynchronously reads the content and returns the Base64 decoded binary bytes.
Returns The number of bytes written to the buffer.
buffer
The buffer into which to copy the resulting text. This value cannot be <see langword="null" /> .
index
The offset into the buffer where to start copying the result.
count
The maximum number of bytes to copy into the buffer. The actual number of bytes copied is returned from this method.
public
int
ReadContentAsBinHex​(byte[] buffer,
int index,
int count)
Reads the content and returns the <see langword="BinHex" /> decoded binary bytes.
Returns The number of bytes written to the buffer.
buffer
The buffer into which to copy the resulting text. This value cannot be <see langword="null" /> .
index
The offset into the buffer where to start copying the result.
count
The maximum number of bytes to copy into the buffer. The actual number of bytes copied is returned from this method.
public
Threading.​Tasks.​Task<​int>
ReadContentAsBinHexAsync​(byte[] buffer,
int index,
int count)
Asynchronously reads the content and returns the <see langword="BinHex" /> decoded binary bytes.
Returns The number of bytes written to the buffer.
buffer
The buffer into which to copy the resulting text. This value cannot be <see langword="null" /> .
index
The offset into the buffer where to start copying the result.
count
The maximum number of bytes to copy into the buffer. The actual number of bytes copied is returned from this method.
public
bool
ReadContentAsBoolean​()
Reads the text content at the current position as a <see langword="Boolean" /> .
Returns The text content as a <see cref="T:System.Boolean" /> object.
public
DateTime
ReadContentAsDateTime​()
Reads the text content at the current position as a <see cref="T:System.DateTime" /> object.
Returns The text content as a <see cref="T:System.DateTime" /> object.
public
DateTimeOffset
ReadContentAsDateTimeOffset​()
Reads the text content at the current position as a <see cref="T:System.DateTimeOffset" /> object.
Returns The text content as a <see cref="T:System.DateTimeOffset" /> object.
public
decimal
ReadContentAsDecimal​()
Reads the text content at the current position as a <see cref="T:System.Decimal" /> object.
Returns The text content at the current position as a <see cref="T:System.Decimal" /> object.
public
double
ReadContentAsDouble​()
Reads the text content at the current position as a double-precision floating-point number.
Returns The text content as a double-precision floating-point number.
public
Single
ReadContentAsFloat​()
Reads the text content at the current position as a single-precision floating point number.
Returns The text content at the current position as a single-precision floating point number.
public
int
ReadContentAsInt​()
Reads the text content at the current position as a 32-bit signed integer.
Returns The text content as a 32-bit signed integer.
public
long
ReadContentAsLong​()
Reads the text content at the current position as a 64-bit signed integer.
Returns The text content as a 64-bit signed integer.
public
object
ReadContentAsObject​()
Reads the text content at the current position as an <see cref="T:System.Object" /> .
Returns The text content as the most appropriate common language runtime (CLR) object.
public
Threading.​Tasks.​Task<​object>
ReadContentAsObjectAsync​()
Asynchronously reads the text content at the current position as an <see cref="T:System.Object" /> .
Returns The text content as the most appropriate common language runtime (CLR) object.
public
string
ReadContentAsString​()
Reads the text content at the current position as a <see cref="T:System.String" /> object.
Returns The text content as a <see cref="T:System.String" /> object.
public
Threading.​Tasks.​Task<​string>
ReadContentAsStringAsync​()
Asynchronously reads the text content at the current position as a <see cref="T:System.String" /> object.
Returns The text content as a <see cref="T:System.String" /> object.
public
object
ReadElementContentAs​(Type returnType,
IXmlNamespaceResolver namespaceResolver)
Reads the element content as the requested type.
Returns The element content converted to the requested typed object.
returnType
The type of the value to be returned.
Note With the release of the .NET Framework 3.5, the value of the <paramref name="returnType" /> parameter can now be the <see cref="T:System.DateTimeOffset" /> type.
namespaceResolver
An <see cref="T:System.Xml.IXmlNamespaceResolver" /> object that is used to resolve any namespace prefixes related to type conversion.
public
object
ReadElementContentAs​(Type returnType,
IXmlNamespaceResolver namespaceResolver,
string localName,
string namespaceURI)
Checks that the specified local name and namespace URI matches that of the current element, then reads the element content as the requested type.
Returns The element content converted to the requested typed object.
returnType
The type of the value to be returned.
Note With the release of the .NET Framework 3.5, the value of the <paramref name="returnType" /> parameter can now be the <see cref="T:System.DateTimeOffset" /> type.
namespaceResolver
An <see cref="T:System.Xml.IXmlNamespaceResolver" /> object that is used to resolve any namespace prefixes related to type conversion.
localName
The local name of the element.
namespaceURI
The namespace URI of the element.
public
Threading.​Tasks.​Task<​object>
ReadElementContentAsAsync​(Type returnType,
IXmlNamespaceResolver namespaceResolver)
Asynchronously reads the element content as the requested type.
Returns The element content converted to the requested typed object.
returnType
The type of the value to be returned.
namespaceResolver
An <see cref="T:System.Xml.IXmlNamespaceResolver" /> object that is used to resolve any namespace prefixes related to type conversion.
public
int
ReadElementContentAsBase64​(byte[] buffer,
int index,
int count)
Reads the element and decodes the <see langword="Base64" /> content.
Returns The number of bytes written to the buffer.
buffer
The buffer into which to copy the resulting text. This value cannot be <see langword="null" /> .
index
The offset into the buffer where to start copying the result.
count
The maximum number of bytes to copy into the buffer. The actual number of bytes copied is returned from this method.
public
Threading.​Tasks.​Task<​int>
ReadElementContentAsBase64Async​(byte[] buffer,
int index,
int count)
Asynchronously reads the element and decodes the <see langword="Base64" /> content.
Returns The number of bytes written to the buffer.
buffer
The buffer into which to copy the resulting text. This value cannot be <see langword="null" /> .
index
The offset into the buffer where to start copying the result.
count
The maximum number of bytes to copy into the buffer. The actual number of bytes copied is returned from this method.
public
int
ReadElementContentAsBinHex​(byte[] buffer,
int index,
int count)
Reads the element and decodes the <see langword="BinHex" /> content.
Returns The number of bytes written to the buffer.
buffer
The buffer into which to copy the resulting text. This value cannot be <see langword="null" /> .
index
The offset into the buffer where to start copying the result.
count
The maximum number of bytes to copy into the buffer. The actual number of bytes copied is returned from this method.
public
Threading.​Tasks.​Task<​int>
ReadElementContentAsBinHexAsync​(byte[] buffer,
int index,
int count)
Asynchronously reads the element and decodes the <see langword="BinHex" /> content.
Returns The number of bytes written to the buffer.
buffer
The buffer into which to copy the resulting text. This value cannot be <see langword="null" /> .
index
The offset into the buffer where to start copying the result.
count
The maximum number of bytes to copy into the buffer. The actual number of bytes copied is returned from this method.
public
bool
ReadElementContentAsBoolean​()
Reads the current element and returns the contents as a <see cref="T:System.Boolean" /> object.
Returns The element content as a <see cref="T:System.Boolean" /> object.
public
bool
ReadElementContentAsBoolean​(string localName,
string namespaceURI)
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 <see cref="T:System.Boolean" /> object.
Returns The element content as a <see cref="T:System.Boolean" /> object.
localName
The local name of the element.
namespaceURI
The namespace URI of the element.
public
DateTime
ReadElementContentAsDateTime​()
Reads the current element and returns the contents as a <see cref="T:System.DateTime" /> object.
Returns The element content as a <see cref="T:System.DateTime" /> object.
public
DateTime
ReadElementContentAsDateTime​(string localName,
string namespaceURI)
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 <see cref="T:System.DateTime" /> object.
Returns The element contents as a <see cref="T:System.DateTime" /> object.
localName
The local name of the element.
namespaceURI
The namespace URI of the element.
public
decimal
ReadElementContentAsDecimal​()
Reads the current element and returns the contents as a <see cref="T:System.Decimal" /> object.
Returns The element content as a <see cref="T:System.Decimal" /> object.
public
decimal
ReadElementContentAsDecimal​(string localName,
string namespaceURI)
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 <see cref="T:System.Decimal" /> object.
Returns The element content as a <see cref="T:System.Decimal" /> object.
localName
The local name of the element.
namespaceURI
The namespace URI of the element.
public
double
ReadElementContentAsDouble​()
Reads the current element and returns the contents as a double-precision floating-point number.
Returns The element content as a double-precision floating-point number.
public
double
ReadElementContentAsDouble​(string localName,
string namespaceURI)
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.
Returns The element content as a double-precision floating-point number.
localName
The local name of the element.
namespaceURI
The namespace URI of the element.
public
Single
ReadElementContentAsFloat​()
Reads the current element and returns the contents as single-precision floating-point number.
Returns The element content as a single-precision floating point number.
public
Single
ReadElementContentAsFloat​(string localName,
string namespaceURI)
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.
Returns The element content as a single-precision floating point number.
localName
The local name of the element.
namespaceURI
The namespace URI of the element.
public
int
ReadElementContentAsInt​()
Reads the current element and returns the contents as a 32-bit signed integer.
Returns The element content as a 32-bit signed integer.
public
int
ReadElementContentAsInt​(string localName,
string namespaceURI)
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.
Returns The element content as a 32-bit signed integer.
localName
The local name of the element.
namespaceURI
The namespace URI of the element.
public
long
ReadElementContentAsLong​()
Reads the current element and returns the contents as a 64-bit signed integer.
Returns The element content as a 64-bit signed integer.
public
long
ReadElementContentAsLong​(string localName,
string namespaceURI)
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.
Returns The element content as a 64-bit signed integer.
localName
The local name of the element.
namespaceURI
The namespace URI of the element.
public
object
ReadElementContentAsObject​()
Reads the current element and returns the contents as an <see cref="T:System.Object" /> .
Returns A boxed common language runtime (CLR) object of the most appropriate type. The <see cref="P:System.Xml.XmlReader.ValueType" /> property determines the appropriate CLR type. If the content is typed as a list type, this method returns an array of boxed objects of the appropriate type.
public
object
ReadElementContentAsObject​(string localName,
string namespaceURI)
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 <see cref="T:System.Object" /> .
Returns A boxed common language runtime (CLR) object of the most appropriate type. The <see cref="P:System.Xml.XmlReader.ValueType" /> property determines the appropriate CLR type. If the content is typed as a list type, this method returns an array of boxed objects of the appropriate type.
localName
The local name of the element.
namespaceURI
The namespace URI of the element.
public
Threading.​Tasks.​Task<​object>
ReadElementContentAsObjectAsync​()
Asynchronously reads the current element and returns the contents as an <see cref="T:System.Object" /> .
Returns A boxed common language runtime (CLR) object of the most appropriate type. The <see cref="P:System.Xml.XmlReader.ValueType" /> property determines the appropriate CLR type. If the content is typed as a list type, this method returns an array of boxed objects of the appropriate type.
public
string
ReadElementContentAsString​()
Reads the current element and returns the contents as a <see cref="T:System.String" /> object.
Returns The element content as a <see cref="T:System.String" /> object.
public
string
ReadElementContentAsString​(string localName,
string namespaceURI)
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 <see cref="T:System.String" /> object.
Returns The element content as a <see cref="T:System.String" /> object.
localName
The local name of the element.
namespaceURI
The namespace URI of the element.
public
Threading.​Tasks.​Task<​string>
ReadElementContentAsStringAsync​()
Asynchronously reads the current element and returns the contents as a <see cref="T:System.String" /> object.
Returns The element content as a <see cref="T:System.String" /> object.
public
string
ReadElementString​()
Reads a text-only element. However, we recommend that you use the <see cref="M:System.Xml.XmlReader.ReadElementContentAsString" /> method instead, because it provides a more straightforward way to handle this operation.
Returns The text contained in the element that was read. An empty string if the element is empty.
public
string
ReadElementString​(string name)
Checks that the <see cref="P:System.Xml.XmlReader.Name" /> property of the element found matches the given string before reading a text-only element. However, we recommend that you use the <see cref="M:System.Xml.XmlReader.ReadElementContentAsString" /> method instead, because it provides a more straightforward way to handle this operation.
Returns The text contained in the element that was read. An empty string if the element is empty.
name
The name to check.
public
string
ReadElementString​(string localname,
string ns)
Checks that the <see cref="P:System.Xml.XmlReader.LocalName" /> and <see cref="P:System.Xml.XmlReader.NamespaceURI" /> properties of the element found matches the given strings before reading a text-only element. However, we recommend that you use the <see cref="M:System.Xml.XmlReader.ReadElementContentAsString(System.String,System.String)" /> method instead, because it provides a more straightforward way to handle this operation.
Returns The text contained in the element that was read. An empty string if the element is empty.
localname
The local name to check.
ns
The namespace URI to check.
public
void
ReadEndElement​()
Checks that the current content node is an end tag and advances the reader to the next node.
public
string
ReadInnerXml​()
When overridden in a derived class, reads all the content, including markup, as a string.
Returns All the XML content, including markup, in the current node. If the current node has no children, an empty string is returned.
If the current node is neither an element nor attribute, an empty string is returned.
public
Threading.​Tasks.​Task<​string>
ReadInnerXmlAsync​()
Asynchronously reads all the content, including markup, as a string.
Returns All the XML content, including markup, in the current node. If the current node has no children, an empty string is returned.
public
string
ReadOuterXml​()
When overridden in a derived class, reads the content, including markup, representing this node and all its children.
Returns If the reader is positioned on an element or an attribute node, this method returns all the XML content, including markup, of the current node and all its children; otherwise, it returns an empty string.
public
Threading.​Tasks.​Task<​string>
ReadOuterXmlAsync​()
Asynchronously reads the content, including markup, representing this node and all its children.
Returns If the reader is positioned on an element or an attribute node, this method returns all the XML content, including markup, of the current node and all its children; otherwise, it returns an empty string.
public
void
ReadStartElement​()
Checks that the current node is an element and advances the reader to the next node.
public
void
ReadStartElement​(string name)
Checks that the current content node is an element with the given <see cref="P:System.Xml.XmlReader.Name" /> and advances the reader to the next node.
name
The qualified name of the element.
public
void
ReadStartElement​(string localname,
string ns)
Checks that the current content node is an element with the given <see cref="P:System.Xml.XmlReader.LocalName" /> and <see cref="P:System.Xml.XmlReader.NamespaceURI" /> and advances the reader to the next node.
localname
The local name of the element.
ns
The namespace URI of the element.
public
string
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 <see cref="Overload:System.Xml.XmlReader.ReadElementContentAsString" /> method instead, because it provides a more straightforward way to handle this operation.
Returns The contents of the element or an empty string.
public
XmlReader
ReadSubtree​()
Returns a new <see langword="XmlReader" /> instance that can be used to read the current node, and all its descendants.
Returns A new XML reader instance set to <see cref="F:System.Xml.ReadState.Initial" /> . Calling the <see cref="M:System.Xml.XmlReader.Read" /> method positions the new reader on the node that was current before the call to the <see cref="M:System.Xml.XmlReader.ReadSubtree" /> method.
public
bool
ReadToDescendant​(string name)
Advances the <see cref="T:System.Xml.XmlReader" /> to the next descendant element with the specified qualified name.
Returns <see langword="true" /> if a matching descendant element is found; otherwise <see langword="false" /> . If a matching descendant element is not found, the <see cref="T:System.Xml.XmlReader" /> is positioned on the end tag ( <see cref="P:System.Xml.XmlReader.NodeType" /> is <see langword="XmlNodeType.EndElement" /> ) of the element.
If the <see cref="T:System.Xml.XmlReader" /> is not positioned on an element when <see cref="M:System.Xml.XmlReader.ReadToDescendant(System.String)" /> was called, this method returns <see langword="false" /> and the position of the <see cref="T:System.Xml.XmlReader" /> is not changed.
name
The qualified name of the element you wish to move to.
public
bool
ReadToDescendant​(string localName,
string namespaceURI)
Advances the <see cref="T:System.Xml.XmlReader" /> to the next descendant element with the specified local name and namespace URI.
Returns <see langword="true" /> if a matching descendant element is found; otherwise <see langword="false" /> . If a matching descendant element is not found, the <see cref="T:System.Xml.XmlReader" /> is positioned on the end tag ( <see cref="P:System.Xml.XmlReader.NodeType" /> is <see langword="XmlNodeType.EndElement" /> ) of the element.
If the <see cref="T:System.Xml.XmlReader" /> is not positioned on an element when <see cref="M:System.Xml.XmlReader.ReadToDescendant(System.String,System.String)" /> was called, this method returns <see langword="false" /> and the position of the <see cref="T:System.Xml.XmlReader" /> is not changed.
localName
The local name of the element you wish to move to.
namespaceURI
The namespace URI of the element you wish to move to.
public
bool
ReadToFollowing​(string name)
Reads until an element with the specified qualified name is found.
Returns <see langword="true" /> if a matching element is found; otherwise <see langword="false" /> and the <see cref="T:System.Xml.XmlReader" /> is in an end of file state.
name
The qualified name of the element.
public
bool
ReadToFollowing​(string localName,
string namespaceURI)
Reads until an element with the specified local name and namespace URI is found.
Returns <see langword="true" /> if a matching element is found; otherwise <see langword="false" /> and the <see cref="T:System.Xml.XmlReader" /> is in an end of file state.
localName
The local name of the element.
namespaceURI
The namespace URI of the element.
public
bool
ReadToNextSibling​(string name)
Advances the <see langword="XmlReader" /> to the next sibling element with the specified qualified name.
Returns <see langword="true" /> if a matching sibling element is found; otherwise <see langword="false" /> . If a matching sibling element is not found, the <see langword="XmlReader" /> is positioned on the end tag ( <see cref="P:System.Xml.XmlReader.NodeType" /> is <see langword="XmlNodeType.EndElement" /> ) of the parent element.
name
The qualified name of the sibling element you wish to move to.
public
bool
ReadToNextSibling​(string localName,
string namespaceURI)
Advances the <see langword="XmlReader" /> to the next sibling element with the specified local name and namespace URI.
Returns <see langword="true" /> if a matching sibling element is found; otherwise, <see langword="false" /> . If a matching sibling element is not found, the <see langword="XmlReader" /> is positioned on the end tag ( <see cref="P:System.Xml.XmlReader.NodeType" /> is <see langword="XmlNodeType.EndElement" /> ) of the parent element.
localName
The local name of the sibling element you wish to move to.
namespaceURI
The namespace URI of the sibling element you wish to move to.
public
int
ReadValueChunk​(char[] buffer,
int index,
int count)
Reads large streams of text embedded in an XML document.
Returns The number of characters read into the buffer. The value zero is returned when there is no more text content.
buffer
The array of characters that serves as the buffer to which the text contents are written. This value cannot be <see langword="null" /> .
index
The offset within the buffer where the <see cref="T:System.Xml.XmlReader" /> can start to copy the results.
count
The maximum number of characters to copy into the buffer. The actual number of characters copied is returned from this method.
public
Threading.​Tasks.​Task<​int>
ReadValueChunkAsync​(char[] buffer,
int index,
int count)
Asynchronously reads large streams of text embedded in an XML document.
Returns The number of characters read into the buffer. The value zero is returned when there is no more text content.
buffer
The array of characters that serves as the buffer to which the text contents are written. This value cannot be <see langword="null" /> .
index
The offset within the buffer where the <see cref="T:System.Xml.XmlReader" /> can start to copy the results.
count
The maximum number of characters to copy into the buffer. The actual number of characters copied is returned from this method.
public
void
ResolveEntity​()
When overridden in a derived class, resolves the entity reference for <see langword="EntityReference" /> nodes.
public
void
Skip​()
Skips the children of the current node.
SkipAsync​()
Asynchronously skips the children of the current node.
Returns The current node.
public
bool
Equals​(object obj)
Inherited from object
protected
void
Finalize​()
Inherited from object
public
int
GetHashCode​()
Inherited from object
protected
object
MemberwiseClone​()
Inherited from object
public
string
ToString​()
Inherited from object