My error is: Unable to cast object of type ‘System.Xml.Linq.XDocument’ to type
I’m trying to execute this code:
XmlSerializer s1 = new XmlSerializer(typeof(xdoc.toString()));
where xdoc has this value:
<root>
<row1>
<ing>john</ing>
</row1>
<row1>
<ing>some name</ing>
</row1>
<row>
<name>salad</name>
<ID>8</ID>
</row>
</root>
I created a class which like this:
class Print {
List<row1> row1 = new List<row1>();
List<row> row = new List<row>();
}
public class row1
{
public string ing { get; set; }
}
public class row
{
public string name { get; set; }
public string ID { get; set; }
}
But it doesn’t work. What am I doing wrong?
You don’t need XmlSerializer when you have XDocument. Linq is enough