我希望使用XmlSerializer对象将嵌套元素中的多个XML属性映射到单个POCO类中.
XML
<products grand-total="100">
<one price="50" />
<two price="20" />
<tree price="30" />
</products>
Run Code Online (Sandbox Code Playgroud)
POCO
public class Product
{
public int GrandTotal { get; set; }
public int OnePrice { get; set; }
public int TwoPrice { get; set; }
public int ThreePrice { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
C#
var doc = XDocument.Load("XmlDoc.xml");
var serializer = new XmlSerializer(typeof(Product));
var reader = doc.Root.CreateReader();
var temp = (Product)serializer.Deserialize(reader);
Run Code Online (Sandbox Code Playgroud)
如果有人知道如何做到这一点,那将是非常棒的.
谢谢.