在net当中使用XmlSerializer类可以将实体类进行序列化可以比较方便的操作xml文件
其中xml文件中不同的节点对应不同的实体类相同有序的节点对应着实体类的集合类demo如下:
booksxml 文件
< xml version=
encoding=
utf
>
<books>
<book bookname=c++语言编程 author=AAAA Date=></book>
<book bookname=Java语言编程 author=BBBB Date=></book>
<book bookname=C#语言编程 author=CCCC Date=></book>
</books>
与之相对应的实体类及操作
Bookscs
Bookscs
[XmlRoot(books)]
public class Books:List<Book>
{
public static Books LoadConfig(string file)
{
XmlSerializer xs = new XmlSerializer(typeof(Books));
StreamReader sr = new StreamReader(file);
Books config = xsDeserialize(sr) as Books;
srClose();
return config;
}
public void SaveConfig(string file)
{
XmlSerializer xs = new XmlSerializer(typeof)