读取xml文件转成List<T>对象的两种方法(附源码)
读取xml文件,是项目中经常要用到的,所以就总结一下,最近项目中用到的读取xml文件并且转成List<T>对象的方法,加上自己知道的另一种实现方法。
就以一个简单的xml做例子。
xml格式如下:
1 <?xml version="1.0"?> 2 <products> 3 product name="West Side Story" price="9.99" supplierId="1" /> 4 ="Assassins"="14.99"="2" 5 ="Frogs"="13.99"6 ="Sweeney Todd"="10.99"="3" 7 </>
Product对象如下:
1 public class Product
{
3 string Name { get; set; }
4
5 decimal Price { 6
7 decimal SupplierId { 8 }