Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1083737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:28:25+00:00 2026-05-16T22:28:25+00:00

I am trying to extract data from XML file and save it my C#

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:28:26+00:00Added an answer on May 16, 2026 at 10:28 pm

    If the DescriptionAttributes matches exactly with the type attribute strings in the XML you can use reflection.

    Edit: convert to generic

    public TEnum GetEnum<TEnum>(string input) where TEnum : struct
    {
        if (!typeof(TEnum).IsEnum)
            throw new Exception(typeof(TEnum).GetType() + " is not en enum");
        Type dataType = Enum.GetUnderlyingType(typeof(typesectionEnum));
        foreach (FieldInfo field in
            typeof(typesectionEnum).GetFields(BindingFlags.Static | BindingFlags.GetField |
            BindingFlags.Public))
        {
            object value = field.GetValue(null);
            foreach (DescriptionAttribute attrib in field.GetCustomAttributes(true).OfType<DescriptionAttribute>())
            {
                if (attrib.Description == input)
                {
                    return (TEnum)value;
                }
            }
        }
        return default(TEnum);
    }
    

    and then call it like this:

    select new Claim 
    {
        id = d.Attribute("id").value,
        type = GetEnum<typesectionEnum>(d.Attribute("type").value),
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to extract data from xml file that looks like this (see
I'm trying to extract data from an xml file. The problem is I know
I'm trying to extract data from an xml file. A sample of my code
I am trying to extract data from a xml file, get rid of the
I'm trying to extract a small amount of data from an XML file into
I have been trying to extract data from a database and fill in a
I am trying to extract an XML node from a URI reference. This URI
I'm trying to create a C# application that extracts data from pages like this
I've got a xml that I'm parsing and trying to extract some data from.
I'm trying to extract some information from an xml file using xslt. I've used

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.