System.Xml.XmlTextReader.ReadString Method

Reads the contents of an element or a text node as a string.

Syntax

public override string ReadString ()

Returns

The contents of the element or text node. This can be an empty string if the reader is positioned on something other than an element or text node, or if there is no more text content to return in the current context.

Note: The text node can be either an element or an attribute text node.

Exceptions

TypeReason
InvalidOperationExceptionAn invalid operation was attempted.
System.Xml.XmlExceptionAn error occurred while parsing the XML.

Remarks

Note:

In the dnprdnext release, the recommended practice is to create System.Xml.XmlReader instances using the erload:System.Xml.XmlReader.Create method. This allows you to take full advantage of the new features introduced in this release. For more information, see Creating XML Readers.

If positioned on an element, ReadString concatenates all text, significant white space, white space, and CData section node types together and returns the concatenated data as the element content. It stops when any markup is encountered, including comments and processing instructions. This could occur in a mixed content model, or when an element end tag is read.

If positioned on a text node, ReadString performs the same concatenation from the text node to the element end tag. If the reader is positioned on an attribute text node, ReadString has the same functionality as if the reader were position on the element start tag. It returns all the concatenated element text nodes.

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 2.0.0.0, 4.0.0.0
Since: .NET 2.0