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 8299073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T16:01:04+00:00 2026-06-08T16:01:04+00:00

I have some XML which looks like this: <Stat Type=first_name>[Value]</Stat> <Stat Type=last_name>[Value]</Stat> <Stat Type=known_name>[Value]</Stat>

  • 0

I have some XML which looks like this:

<Stat Type="first_name">[Value]</Stat>
<Stat Type="last_name">[Value]</Stat>
<Stat Type="known_name">[Value]</Stat>

I want to deserialize this to an object. As there is one element name called “Stat” it’s making it difficult to get something like:

[XmlAttribute("first_name")]
public string FirstName{get;set;}

[XmlAttribute("last_name")]
public string LastName{get;set;}

[XmlAttribute("known_name")]
public string KnownName{get;set;}

Is there a way of getting the XML above into an object like:

public string FirstName{get;set;}
public string LastName{get;set;}
public string KnownName{get;set;}

Thanks.

  • 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-06-08T16:01:05+00:00Added an answer on June 8, 2026 at 4:01 pm

    I managed to solve this by using an extension. Not ideal. I get the list of stats:

    [XmlElement("Stat")]
    public List<Stat> Stats { get; set;}
    

    Then I have separate properties like:

    public string FirstName
    {
       get { return Stats.GetStat("first_name"); }
    }
    

    The GetStat extension method on the Stats property then gets the relevant key. Unfortunately, this way, it will run through that list for each property I want to get.

    public static string GetStat(this List<Stat> stats, string key)
    {
      var val = stats.FirstOrDefault(item => item.Type == key);
    
      if (val != null)
        return val.Value ?? String.Empty;
      return String.Empty;
    } 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some data in an XML element that looks like this: <item value=category1,category2>Item
I have some XML which contains records and sub records, like this: <data> <record
I have some data which looks like: <data> <row> <v>0.0264</v> <v>1073655665.0000</v> <!-- select this
I have a document which when simplified looks like this: <?xml version=1.0?> <document> <br/>
I have some xml that looks like this: <?xml version=1.0?> <data> <items> <item><timestamp>2011-07-11T09:01:42Z</timestamp><title><![CDATA[ some
I have some XML code that looks like this <SEARCHRESULTS> <FUNCTION name=BarGraph> <PARAMETER name=numList></PARAMETER>
I have XML which looks like this: <A></A> <A></A> <A> <a/> <a/> </A> As
I have a method in my Controller which looks like this: @RequestMapping(value = /test,
I have an xml file which looks like this: <section> <title> title of section
I have a sample xml file that looks like this: <Books> <Category Genre=Fiction BookName=book_name

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.