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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:38:00+00:00 2026-05-22T18:38:00+00:00

I have 4 small classes to deserialize xml from an incomming xml poll, to

  • 0

I have 4 small classes to deserialize xml from an incomming xml poll, to usable classes to build up the poll.

now, i know how to set a property from a class, to match a certain attribute or element in the xml, and if that element is just a string thats easy
but what if the element also has an attribute like in the following example?

<Questions>
 <Question id="a guid">
  <AnswerItems>
   <AnswerItem Id="a guid">3</AnswerItem>
   <AnswerItem Id="a guid">2</AnswerItem>
   <AnswerItem Id="a guid">5</AnswerItem>
  </AnswerItems>
 </Question>
</Questions>

the question class would look like this:

[Serializable()]
public class Question
{
    [XmlAttribute("Id")]
    public Guid QuestionId { get; set; }

    [XmlArray("AnswerItems")]
    [XmlArrayItem("AnswerItem", typeof(AnswerItem))]
    public AnswerItem[] AnswerItems { get; set; }
}

[Serializable()]
public class AnswerItem
{
    [XmlAttribute("Id")]
    public Guid QuestionId { get; set; }

    // how do i fetch the value of this node? 
    // its not a XmlElement and it's not an XmlValue
}

Ok, so the value of an AnswerItem node, that is what i want to get as well.
i could easily not use the AnswerItem class, and just use an XmlArray AnswerItems of the type String and put the values in the array, but then i would lose the AnswerItem’s Id Attribute.

  • 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-22T18:38:01+00:00Added an answer on May 22, 2026 at 6:38 pm

    In AnswerItem, make a property called Value and mark it with the XmlText attribute. This setting will cause the XmlSerializer to read the text in the AnswerItem element into the Value property.

    [Serializable()]
    public class AnswerItem
    {
        [XmlAttribute("Id")]
        public Guid QuestionId { get; set; }
    
        [XmlText]
        public string Value { get; set; }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Ruby I have often written a number of small classes, and had a
I have many small files containing code fragments, pseudo-code algorithms, classes, templates, SQL-samples, etc.,
I have a small utility that I use to download an MP3 file from
I have small page which has label, DropDownList and a submit button. <div> <asp:label
I have small problem with my .net 2.0 winforms application. I want to embed
Where I work, we have small teams of 2 - 5 people. As a
I have a small JS function that does Ajax for me and another like
I have a small local network. Only one of the machines is available to
I have a small VB.NET application that I'm working on using the full version
I have a small diagnostic VB.Net application ( 2 forms, 20 subs & functions)

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.