I have the following xml file
<?xml version="1.0" encoding="utf-8"?>
<root>
<file_1>
<file_name Value="" />
<date Value="" />
<information>
<page1>
<percentage Value="90%" />
<profit Value="50%" />
<total Value="$1500" />
</page1>
</information>
</file_1>
</root>
and I want to serialize that xml but I want that all subnodes in page1 node could be handle like properties, for example:
var xmlInfo = new List<xmlClass>();
var FieldName = xmlInfo[0].FieldName; // the value of FieldName should be percentage
var data = xmlInfo[0].Value; // the value of data should be 90%
In other words, I'm only interested in the deepest nodes to serialize them into an object.
I have a serialization method, but I don't know how to build the class.
public static T Deserialize<T>(XDocument doc)
{
XmlSerializer xmlSerializer = new XmlSerializer(typeof(T));
using (var reader = doc.Root.CreateReader())
{
return (T)xmlSerializer.Deserialize(reader);
}
}