I have an XML file that looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<response uri="/crm/private/xml/Leads/getRecords">
<Leads>
<row no="1">
<FL val="LEADID">2000000022020</FL>
<FL val="SMOWNERID">2000000018005</FL>
<FL val="Lead Owner">John</FL>
<FL val="Company">Zillium</FL>
<FL val="First Name">Scott</FL>
<FL val="Last Name">James</FL>
<FL val="Designation">null</FL>
<FL val="Email">null</FL>
<FL val="Phone">null</FL>
<FL val="Fax">null</FL>
<FL val="Mobile">null</FL>
<FL val="Website">null</FL>
<FL val="Lead Source">null</FL>
<FL val="Lead Status">null</FL>
<FL val="No of Employees">0</FL>
<FL val="Annual Revenue">0.0</FL>
</row>
<row no="2">
<FL val="LEADID">2000000022020</FL>
<FL val="SMOWNERID">2000000018005</FL>
<FL val="Lead Owner">John</FL>
<FL val="Company">Zillium</FL>
<FL val="First Name">Scott</FL>
<FL val="Last Name">James</FL>
<FL val="Designation">null</FL>
<FL val="Email">null</FL>
<FL val="Phone">null</FL>
<FL val="Fax">null</FL>
<FL val="Mobile">null</FL>
<FL val="Website">null</FL>
<FL val="Lead Source">null</FL>
<FL val="Lead Status">null</FL>
<FL val="No of Employees">0</FL>
<FL val="Annual Revenue">0.0</FL>
</row>
</Leads>
</response>
I am trying to read the "key/value" pairs in the row element, but I can't seem to get at grasp on how to do it using Linq.
I need to "de-serialize" the data into a simple POCO
public class Leads
{
public long LEADID { get; set; }
public long SMOWNERID { get; set; }
public string LeadOwner { get; set; }
public string Company { get; set; }
public string FirstName { get; set; }
public string LastName { get; set; }
public string Designation { get; set; }
public string Email { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
public string Mobile { get; set; }
public string Website { get; set; }
public string LeadSource { get; set; }
public string LeadStatus { get; set; }
public int NoOfEmployees { get; set; }
public decimal AnnualRevenue { get; set; }
}
My problem is, that all the elements have the same name so I need to get the attribut value (val) paired with the element value.
So my question is, is there a smart way to do this using Linq.
Otherwise my workaround would be to write an XLS and transform the XML into a more de-serializeable XML format.