XmlReader.ReadContentAsString 方法

定义

将当前位置的文本内容作为 String 对象读取。Reads the text content at the current position as a String object.

public:
 virtual System::String ^ ReadContentAsString();
public virtual string ReadContentAsString ();
abstract member ReadContentAsString : unit -> string
override this.ReadContentAsString : unit -> string
Public Overridable Function ReadContentAsString () As String

返回

String

作为 String 对象的文本内容。The text content as a String object.

例外

试图进行的强制转换无效。The attempted cast is not valid.

该字符串格式无效。The string format is not valid.

在上一次异步操作完成之前调用了 XmlReader 方法。An XmlReader method was called before a previous asynchronous operation finished. 在此情况下,会引发 InvalidOperationException 并显示消息“异步操作已在进行中。”In this case, InvalidOperationException is thrown with the message "An asynchronous operation is already in progress."

注解

此方法连接文本、空格、有效空白和 CDATA 部分,并跳过任何注释或处理指令。This method concatenates text, white space, significant white space, and CDATA sections, and skips any comments or processing instructions. 实体引用会自动得到解决。Entity references are automatically resolved.

此方法可用于将类型化值转换为字符串,或在跳过注释和处理指令时读取文本内容。This method can be used convert typed values to a string, or to read the text content while skipping comments and processing instructions.

下表描述了此方法如何处理每个节点类型。The following table describes how this method treats each node type.

XmlNodeTypeXmlNodeType 返回值Return value 读取器行为Reader behavior
Text

CDATA

Whitespace

SignificantWhitespace

EntityReference

EndEntity
将文本、CDATA、空白和有效空白节点的串联内容转换为所请求的类型。Concatenated content of text, CDATA, white space and significant white space nodes converted to the requested type. 移至下一个开始元素或结束元素标记。Moves to the next start element or end element tag. 实体引用自动展开。Entity references are automatically expanded.
Attribute XmlConvert.ToXxx 对属性值调用相同。Same as calling XmlConvert.ToXxx on the attribute value. 读取器仍保留在当前位置。The reader remains in the current position.
Comment

ProcessingInstruction
忽略处理指令 (PI) 或注释,读取 PI 或注释后面的串联文本内容。Ignores the processing instruction (PI) or comment and reads the concatenated text content that follows the PI or comment. 移至下一个开始元素或结束元素标记。Moves to the next start element or end element tag. 实体引用自动展开。Entity references are automatically expanded.
EndElement 空字符串。An empty string. 读取器仍保留在当前位置。The reader remains in the current position.
Element

XmlDeclaration

None

Document

DocumentType

Notation

Entity

DocumentFragment
引发 InvalidOperationExceptionAn InvalidOperationException is thrown. 未定义,尽管通常读取器将保留在当前位置。Undefined, although typically the reader remains in the current position.

有关详细信息,请参阅引用页的 "备注" 部分 XmlReaderW3C XML 架构第2部分:数据类型 建议。For more information, see the Remarks section of the XmlReader reference page and the W3C XML Schema Part 2: Datatypes recommendation.

有关此方法的异步版本,请参阅 ReadContentAsStringAsyncFor the asynchronous version of this method, see ReadContentAsStringAsync.

适用于