今天终于搞清楚 XmlTextReader 的 Read 方法读 node 的机制了。他会把读到的回车阿,空格阿什么的都当成是一个Node。以前一直没能很好的理解这一点,所以总觉得有点怪怪的。现在好了,可以安心的睡一觉了。
一下是两端代码的实例:
测试的代码很简单
XmlTextReader BooksReader
=
new
XmlTextReader(
@"
E:\MCAD+MCSD\MCAD\2663\Practices\Mod02\books.xml
"
);

while
(BooksReader.Read())

{
listBox1.Items.Add(BooksReader.Name);
}
//Xml File Version 1
<?
xml version='1.0'
?>
<!--
This file represents a fragment of a book store inventory database
-->
<
bookstore
>
<
book
genre
="autobiography"
publicationdate
="1981"
ISBN
="1-861003-11-0"
>
<
title
>
The Autobiography of Benjamin Franklin
</
title
>
<
author
>
<
first-name
>
Benjamin
</
first-name
>
<
last-name
>
Franklin
</
last-name
>
</
author
>
<
price
>
8.99
</
price
>
</
book
>
<
book
genre
="novel"
publicationdate
="1967"
ISBN
="0-201-63361-2"
>
<
title
>
The Confidence Man
</
title
>
<
author
>
<
first-name
>
Herman
</
first-name
>
<
last-name
>
Melville
</
last-name
>
</
author
>
<
price
>
11.99
</
price
>
</
book
>
<
book
genre
="philosophy"
publicationdate
="1991"
ISBN
="1-861001-57-6"
>
<
title
>
The Gorgias
</
title
>
<
author
>
<
name
>
Plato
</
name
>
</
author
>
<
price
>
9.99
</
price
>
</
book
>
</
bookstore
>
//运行结果
//XML File version 2
<?
xml version='1.0'
?>
<!--
This file represents a fragment of a book store inventory database
-->
<
bookstore
><
book
genre
="autobiography"
publicationdate
="1981"
ISBN
="1-861003-11-0"
>
<
title
>
The Autobiography of Benjamin Franklin
</
title
>
<
author
>
<
first-name
>
Benjamin
</
first-name
>
<
last-name
>
Franklin
</
last-name
>
</
author
>
<
price
>
8.99
</
price
>
</
book
>
<
book
genre
="novel"
publicationdate
="1967"
ISBN
="0-201-63361-2"
>
<
title
>
The Confidence Man
</
title
>
<
author
>
<
first-name
>
Herman
</
first-name
>
<
last-name
>
Melville
</
last-name
>
</
author
>
<
price
>
11.99
</
price
>
</
book
>
<
book
genre
="philosophy"
publicationdate
="1991"
ISBN
="1-861001-57-6"
>
<
title
>
The Gorgias
</
title
>
<
author
>
<
name
>
Plato
</
name
>
</
author
>
<
price
>
9.99
</
price
>
</
book
>
</
bookstore
>

//运行结果
一下是两端代码的实例:
测试的代码很简单








//Xml File Version 1




























//XML File version 2



























