本文整理汇总了C#中System.Xml.XmlTextReader.ReadChars方法的典型用法代码示例。如果您正苦于以下问题:C# XmlTextReader.ReadChars方法的具体用法?C# XmlTextReader.ReadChars怎么用?C# XmlTextReader.ReadChars使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Xml.XmlTextReader
的用法示例。
在下文中一共展示了XmlTextReader.ReadChars方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
//引入命名空间
using System;
using System.Xml;
// Reads an XML document using ReadChars
public class Sample {
private const String filename = "items.xml";
public static void Main() {
XmlTextReader reader = null;
try {
// Declare variables used by ReadChars
Char []buffer;
int iCnt = 0;
int charbuffersize;
// Load the reader with the data file. Ignore white space.
reader = new XmlTextReader(filename);
reader.WhitespaceHandling = WhitespaceHandling.None;
// Set variables used by ReadChars.
charbuffersize = 10;
buffer = new Char[charbuffersize];
// Parse the file. Read the element content
// using the ReadChars method.
reader.MoveToContent();
while ( (iCnt = reader.ReadChars(buffer,0,charbuffersize)) > 0 ) {
// Print out chars read and the buffer contents.
Console.WriteLine (" Chars read to buffer:" + iCnt);
Console.WriteLine (" Buffer: [{0}]", new String(buffer,0,iCnt));
// Clear the buffer.
Array.Clear(buffer,0,charbuffersize);
}
}
finally {
if (reader!=null)
reader.Close();
}
}
} // End class