Note: |
|---|
In the
.NET Framework version 2.0 release, the recommended practice is to create XmlReader instances using the XmlReader..::.Create method. This allows you to take full advantage of the new features introduced in this release. For more information, see Creating XML Readers.
|
This is the most efficient way to process very large streams of text embedded in an XML document. Rather than allocating large string objects, ReadChars returns text content a buffer at a time. This method is designed to work only on element nodes. Other node types cause ReadChars to return 0.
In the following XML, if the reader is positioned on the start tag, ReadChars returns test and positions the reader after the end tag.
ReadChars has the following functionality:
This method is designed to work on element nodes only. Other node types cause ReadChars to return 0.
This method returns the actual character content. There is no attempt to resolve entities, CDATA, or any other markup encountered. ReadChars returns everything between the start tag and the end tag, including markup.
ReadChars ignores XML markup that is not well-formed. For example, when reading the following XML string <A>1<A>2</A>, ReadChars returns 1<A>2</A>. (It returns markup from the matching element pair and ignores others.)
This method does not do any normalization.
When ReadChars has reached the end of the character stream, it returns the value 0 and the reader is positioned after the end tag.
Attribute read methods are not available while using ReadChars.
For example, using the following XML:
<thing>
some text
</thing>
<item>
</item>
The reader is positioned on the <item> element at the end of the while loop.
if (XmlNodeType.Element == reader.NodeType && "thing" == reader.Name)
{
while(0 != reader.ReadChars(buffer, 0, 1)
{
// Do something.
// Attribute values are not available at this point.
}
}