Поделиться через


XmlReader.ReadValueChunk Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Reads large streams of text embedded in an XML document.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

Syntax

'Declaration
Public Overridable Function ReadValueChunk ( _
    buffer As Char(), _
    index As Integer, _
    count As Integer _
) As Integer
public virtual int ReadValueChunk(
    char[] buffer,
    int index,
    int count
)

Parameters

  • buffer
    Type: array<System.Char[]
    The array of characters that serves as the buffer to which the text contents are written. This value cannot be nulla null reference (Nothing in Visual Basic).
  • index
    Type: System.Int32
    The offset within the buffer where the XmlReader can start to copy the results.
  • count
    Type: System.Int32
    The maximum number of characters to copy into the buffer. The actual number of characters copied is returned from this method.

Return Value

Type: System.Int32
The number of characters read into the buffer. The value zero is returned when there is no more text content.

Exceptions

Exception Condition
InvalidOperationException

The current node does not have a value (HasValue is false).

ArgumentNullException

The buffer value is nulla null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

The index into the buffer, or index + count is larger than the allocated buffer size.

NotSupportedException

The XmlReader implementation does not support this method.

XmlException

The XML data is not well-formed.

Remarks

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. 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. Other node type values are cached, including attributes and CDATA nodes.

This method returns only the content of the Value property and does not move the XmlReader.

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. It returns the 0 when it has reached the end of the value. It cannot be restarted to read through the value again.

In between calls to ReadValueChunk the XmlReader properties do no change except for the Value property. 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. All the XmlReader implementations in the System.Xml namespace return a partial value for the Value property implementation.

Any Read method can be called in between calls to ReadValueChunk. If this occurs, the XmlReader moves to the next XmlNodeType in the stream and any characters not yet returned are skipped.

There may be a case when ReadValueChunk returns less than the requested number of characters. 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. The surrogate pair would then be returned in the next ReadValueChunk call. 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.

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.