XmlReader.ReadValueChunk(Char[], Int32, Int32) 方法

定义

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

public:
 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

参数

buffer
Char[]

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

index
Int32

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

count
Int32

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

返回

Int32

读取到缓冲区中的字符数。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."

buffer 值为 nullThe buffer value is null.

缓冲区中的索引或者索引与计数之和大于分配的缓冲区大小。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. 此方法可在任何具有值 () 的节点上调用 HasValue true ,但是,仅当在文本、空白和有效空白节点上调用时才会发生节点值的实际流式处理。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.

在对属性的调用之间, ReadValueChunk XmlReader 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 为属性实现返回一个部分值 ValueAll 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. 例如,如果你的长度为200个字符的长度为个字符的值,并且在位置127和128处调用了,而你 ReadValueChunk 使用了128字符的缓冲区调用,则该方法调用将返回127字符,而不是所请求的128。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. 然后,将在下一次调用时返回代理项对 ReadValueChunkThe 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.

适用于