Compartilhar via


ReadValueChunk

 

This method will read up to a maximum of the specified chunk size (as available) from the value of the current node and copy the value into the specified buffer.

Syntax

  
HRESULT ReadValueChunk ([in] WCHAR * pBuffer, [in] UINT cwhChunkSize, [out] UINT * pcwchRead);  

Arguments

pBuffer
You must pass in a buffer that is at least cwhChunkSize characters long. The value of the token will be read into the buffer.

cwhChunkSize
The chunk size required, in characters. Any value from 0 to 4G is valid for chunk size.

pcwchRead
The size of the string read. This argument cannot be NULL.

Return Value

Returns S_OK if no error is generated. Returns E_PENDING if the data is unavailable, and the stream is paused. Returns S_FALSE if no more content is available to be read.

Remarks

The size of the buffer should be greater than or equal to that of the specified chunk size.

If the remaining value is shorter than the required chunk size, the method will return only the remaining value and notify the call through the pcwchRead argument of its size.

This method will not span a surrogate pair. When the number of characters requested would split a surrogate pair, this method returns one fewer WCHAR than the number requested.

If the content is temporarily unable to be read this method returns E_PENDING and does not move forward.

The following code reads a chunk of a value:

while (TRUE)  
{  
    hr = pReader->ReadValueChunk(buff, buffSize - 1, &charsRead);  
    // This is a sample of how one might handle E_PENDING  
    if (E_PENDING == hr){  
        // Alert user to the pending notification  
        wprintf(L"Error pending, error is %08.8lx", hr);  
  
        // As long as E_PENDING is returned keep trying to read  
  while (hr == E_PENDING){  
            ::Sleep(1000);  
            hr = pReader->ReadValueChunk(buff, buffSize - 1, &charsRead);  
  }  
    }  
    if (S_FALSE == hr || 0 == charsRead)  
        break;  
    if (S_OK != hr)  
    {  
        wprintf(L"\nXmlLite Error: %08.8lx\n", hr);  
        return -1;  
    }  
    buff[charsRead] = L'\0';  
    dotWhiteSpace(buff, charsRead);  
    wprintf(L"attribute chunk size:%d >%s<\n", charsRead, buff);  
}  

Requirements

Header: XmlLite.h

Library: XmlLite.lib

See Also

Read
GetValue
IXmlReader Methods