I have xml files that I need to load and create class objects from, however, these files are formatted in, what seems to me to be a ridiculously nested way. Sadly I can't have the xml files reformatted. Here's what they look like (assume there is only one purchase entry for every customer and the name can serve as a key):
<root>
<start>
<customer>
<store store = "a">
<customer name = "Ted Johnson">
<product product = "shampoo">
<price price = "10">
</ price>
</ product>
</customer>
</store>
<store store = "b">
<customer name = "Janet Henry">
<product product = "soda">
<price price = "2">
</ price>
</ product>
</ customer>
</ store>
</ customer>
<tax>
<store store = "a">
<customer name = "Ted Johnson">
<product product = "shampoo">
<tax tax = "1">
<date date = "4/4/2014">
</date>
</tax>
</ product>
</customer>
</store>
<store store = "b">
<customer name = "Janet Henry">
<product product = "soda">
<tax tax = "0.2">
<date date = "5/5/2014">
</date>
</tax>
</ product>
</customer>
</store>
</tax>
</ start>
</ root>
Now I need to create class objects in c#/WPF, based on this kind of monstrosity. I've been trying a few things but keep running into hurdles, and I'm worried I might end up spending a long time forcing an inefficient solution. Is there an easy way to approach this?
My goal is to create something like the following:
var customerPurchases = (from e in xml.Descendants(ns + "start")
select new customerPurchase
{
name = e.Attribute("name").Value,
store = e.Attribute("store").Value,
product = e.Attribute("product").Value,
price = e.Attribute("price").Value,
tax = e.Attribute("tax").Value,
date = e.Attribute("date").Value,
}).ToList();
Any help or insight on this mess would be greatly appreciated!