I have XML like the following:
<feed>
<products>
<product>
</product>
.
.
.
<product>
</product>
</products>
</feed>
I can deserialize the xml using:
public class feed
{
public ProductList products { get; set; }
}
public class ProductList
{
[XmlElement("product")]
public List<Product> Products { get; set; }
}
var result = (feed)new XmlSerializer(typeof(feed)).Deserialize(xmlReader);
I thought I can use the XML root attribute to control deserialization, i.e,
class Products
{
public List<Product> Products { get; set; }
}
var rootAtrr = new XmlRootAttribute("products");
var result = (Products)new XmlSerializer(typeof(Products), rootAtrr).Deserialize(xmlReader);
or better still:
var result = (List<Product>)new XmlSerializer(typeof(List<Product>), rootAtrr).Deserialize(xmlReader);
All the above changes don't work.
Does that mean the root attribute is specifically for ACTUAL root element in XML not where to start reading?
Also, does that mean the XML document enforce what model class to define? the feed
class in this particular case?
Or am I missing a point or 3?