XmlReader.ReadValueChunk(Char[], Int32, Int32) XmlReader.ReadValueChunk(Char[], Int32, Int32) XmlReader.ReadValueChunk(Char[], Int32, Int32) XmlReader.ReadValueChunk(Char[], Int32, Int32) Method


读取嵌入在 XML 文档中的大量文本流。Reads large streams of text embedded in an XML document.

 virtual int ReadValueChunk(cli::array <char> ^ buffer, int index, int count);
public virtual int ReadValueChunk (char[] buffer, int index, int count);
abstract member ReadValueChunk : char[] * int * int -> int
override this.ReadValueChunk : char[] * int * int -> int
Public Overridable Function ReadValueChunk (buffer As Char(), index As Integer, count As Integer) As Integer



作为文本内容写入到的缓冲区的字符数组。The array of characters that serves as the buffer to which the text contents are written. 此值不能为 nullThis value cannot be null.

Int32 Int32 Int32 Int32

缓冲区中的偏移量,XmlReader 可以从这个位置开始复制结果。The offset within the buffer where the XmlReader can start to copy the results.

Int32 Int32 Int32 Int32

要复制到缓冲区中的最大字符数。The maximum number of characters to copy into the buffer. 此方法返回复制的实际字符数。The actual number of characters copied is returned from this method.


读取到缓冲区中的字符数。The number of characters read into the buffer. 如果不再有文本内容,则返回值零。The value zero is returned when there is no more text content.


当前节点没有值(HasValuefalse)。The current node does not have a value (HasValue is false).

- 或 --or- 在上一次异步操作完成之前调用了 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."

缓冲区中的索引或者索引与计数之和大于分配的缓冲区大小。The index into the buffer, or index + count is larger than the allocated buffer size.

XmlReader 实现不支持此方法。The XmlReader implementation does not support this method.

XML 数据不是格式良好的。The XML data is not well-formed.


此方法,读取非常大的文本流以流的形式,即,XML 文档中嵌入的少量一次而不是为整个值分配单个字符串的字符。This method enables reading of very large streams of text embedded in an XML document in a streaming fashion, that is, a small number of characters at a time instead of allocating a single string for the whole value. 可以具有值的任何节点上调用此方法 (HasValuetrue),但实际的节点值只会发生流式处理文本、 空白和有效空白节点上调用时。This method can be called on any node that has a value (HasValue is true), however actual streaming of the node value only occurs when called on a text, white space and significant white space nodes. 其他节点类型的值进行缓存,包括属性和 CDATA 节点。Other node type values are cached, including attributes and CDATA nodes.

此方法返回的内容Value属性并不会移动XmlReaderThis method returns only the content of the Value property and does not move the XmlReader.

此方法读取指定的数量的字符 (count) 的字符缓冲区的节点值 (buffer) 指定的偏移量处 (index),并返回写入到缓冲区的字符数。This method reads the specified number of characters (count) of the node value into a character buffer (buffer) at a specified offset (index) and returns the number of characters written to the buffer. 它将返回0当它达到值的末尾。It returns the 0 when it has reached the end of the value. 它不能重启以再次读取该值。It cannot be restarted to read through the value again.

在调用之间ReadValueChunkXmlReader属性不会更改除Value属性。In between calls to ReadValueChunk the XmlReader properties do no change except for the Value property. Value属性访问它也可能返回的部分值 (包含字符尚不支持返回ReadValueChunk) 或全部值,具体取决于实现。When the Value property is accessed it may either return a partial value (with characters not yet returned by ReadValueChunk) or a full value depending on the implementation. 所有XmlReader中的实现System.Xml命名空间部分为返回值Value属性实现。All the XmlReader implementations in the System.Xml namespace return a partial value for the Value property implementation.

任何读取方法可以调用之间调用ReadValueChunkAny Read method can be called in between calls to ReadValueChunk. 如果发生这种情况,XmlReader移动到下XmlNodeType中的流,并且还未返回任何字符被跳过。If this occurs, the XmlReader moves to the next XmlNodeType in the stream and any characters not yet returned are skipped.

可能有一种情况时ReadValueChunk返回请求的字符数小于。There may be a case when ReadValueChunk returns less than the requested number of characters. 例如,如果在位置 127 和 128 将代理项对具有 200 个字符长值,您调用ReadValueChunk128 个字符的缓冲区,使用方法调用将返回而不是请求 128 127 个字符。For example, if you had a 200-character long value with a surrogate pair at positions 127 and 128 and you called ReadValueChunk with a 128-character buffer, the method call would return 127 characters instead of the requested 128. 则将在下一步中返回的代理项对ReadValueChunk调用。The surrogate pair would then be returned in the next ReadValueChunk call. 在这种情况下,ReadValueChunk未返回所请求的 128 个字符,因为这样做因此将导致在缓冲区末尾的不完整代理项对。In this case, ReadValueChunk did not return the requested 128 characters because doing so would have resulted in an incomplete surrogate pair at the end of the buffer.

此方法的异步版本,请参阅ReadValueChunkAsyncFor the asynchronous version of this method, see ReadValueChunkAsync.