I am trying to extract data from XML file and save it my C# class/object. My problem is
I have an XMl file like this
<personal_auto xmlns = "http://cp.com/rules/client">
<claim id = "s1" type = "Subject Section">
<report >
</report>
<policy>
</policy>
</claim>
<claim id = "s2" type = "Vehichle Section">
<report >
</report>
<policy>
</policy>
</claim>
<claim id = "s3" type = "Agent Section">>
<report
</report>
<policy>
</policy>
</claim>
</personal_auto>
I have an enum like this
public enum typesectionEnum
{
[Description("Subject Section")]
subjectSection,
[Description("Vehicle Section")]
vehicleSection,
[Description("Possible Related Section")]
possibleRelatedSection,
[Description("Agent (Summary) Section")]
AgentSection
}
I am trying to extract data from the XML file and save to my C# class/object.
List<claim> = ( from d in query.Descendants(xmlns + "claim")
select new Claim
{
id = d.Attribute("id").value,
type = ????
}
).ToList (),
What I am wondering is, I want to set the value in my application that will access the value in the xml file.
If the
DescriptionAttributes matches exactly with the type attribute strings in the XML you can use reflection.Edit: convert to generic
and then call it like this: