I need to read this xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Products>
<Product Name="Prod1">
<Description>Desc1</Description >
<Price>100</Price >
<Stock>200</Stock>
</Product>
<Product Name="Prod2">
<Description>Desc2</Description >
<Price>50</Price >
<Stock>400</Stock>
</Product>
</Products>
my idea was do something like this:
public ICollection<ProductDTO> importtProducts()
{
XmlSerializer deserializer = new XmlSerializer(typeof(List<ProductDTO>));
TextReader textReader = new StreamReader(@"c:\importers\xmlimporter.xml");
List<ProductDTO> prods;
prods = (List<ProductDTO>)deserializer.Deserialize(textReader);
textReader.Close();
XDocument doc = XDocument.Load(@"c:\importers\xmlimporter.xml");
foreach (var prod in doc.Root.Descendants("Product").Distinct())
{
//work with the prod in here
}
return some prods..;
}
but I'm having some problems with the root item, the xmlSerializer type. does someone know which type should I use? List, IList, ICollection, IEnumerable....
thanks a lot!