这个程序不知道如何终止
时间:2010-12-10 来源:cuishengli
books.xml
<?xml version="1.0" encoding="utf-8" ?>
<!--sample XML fragment-->
<bookstore>
<book genre='novel' ISBN='10-861003-324'>
<title>The Handmaid's Tale</title>
<price>19.95</price>
</book>
<book genre='novel' ISBN='1-861001-57-5'>
<title>Pride And Prejudice</title>
<price>24.95</price>
</book>
</bookstore>
代码:
static void TestReadOuterXml() { XmlReaderSettings settings = new XmlReaderSettings(); settings.IgnoreWhitespace = true; using(XmlReader reader = XmlReader.Create("books.xml")) { // Moves the reader to the root element. reader.MoveToContent(); // Moves to book node. reader.Read(); var i=0; while(i<100){ Console.WriteLine("Read the {0} book using ReadOuterXml...",i); Console.WriteLine(reader.ReadOuterXml()); Console.ReadLine(); i++; }; } Console.ReadLine(); }
这个程序假定有许多书,要求一本一本的读出。请问如何读出所有书后退出循环?
相关阅读 更多 +