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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:51:20+00:00 2026-05-24T00:51:20+00:00

I have an xml that has nested tags like the following: <?xml version=1.0 encoding=utf-8

  • 0

I have an xml that has nested tags like the following:

<?xml version="1.0" encoding="utf-8" ?>
<questions>
  <question title="Which of these is a circle?" type="graphics">
    <text>Which of these is a circle?</text>
    <image src="shapes.png" />
    <Answer correct="true">
      <image src="circle.png"/> 
    </Answer>
    <Answer>
      <image src="square.png"/>
    </Answer>
  </question>
  <question title="Click on the circle" type="point">
    <image src="imageOfShapesWithTheAnswerAt200x150withASizeOf20x20.png"/>
    <Answer x="200" y="150" width="20" height="20" correct="true">Circle</Answer>
    <Answer x="100" y="150" width="20" height="20">NotCircle</Answer>
  </question>
  <question title="Trick question" type="text">
    <text>What was the colour of Duke Wellingtons white horse?</text>
    <image src="images.png" />
    <Answer correct="true">White</Answer>
    <Answer>Blue</Answer>
    <Answer>Black</Answer>
    <Answer>Red</Answer>
    <Answer>Green</Answer>
  </question>
</questions>

How would I then serialize it into this class?

    [XmlRoot("quiz")]
    public class Quiz
    {
        public class Question
        {
            public String QuestionText { get; set; }
            public String QuestionTitle { get; set; } // automatic getters and setters (nicer)
            public String QuestionImage { get; set; }

            [XmlArray]
            public List<Answer> Answers { get; set; }
        }

        public class Answer
        {
            public Boolean selected { get; set; }
            public Boolean correct { get; set; }

            [XmlElement("text")]
            public String text { get; set; }
            [XmlElement("image")]
            public String image { get; set; }
        }
    }

I’ve tried using the serializer hence the [XmlElement] and [XmlRoot] in the object but i’m struggling a bit with it.

I’ve seen a lot of examples of serializing into xml but not many from xml to an object.

edit

i’ve found a tutorial for this http://www.jonasjohn.de/snippets/csharp/xmlserializer-example.htm

  • 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-24T00:51:21+00:00Added an answer on May 24, 2026 at 12:51 am
        XDocument dok = XDocument.Load(Server.MapPath("XMLFile.xml"));
        XmlSerializer mySerializer = new XmlSerializer(typeof(Quiz));
        TextReader TW = new StringReader(dok.ToString());
        Quiz quizData= mySerializer.Deserialize(TW) as Quiz;
    

    Deserialize method of the XmlSerializer can do that.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a bunch of XML that has lines that look like this <_char
My question is the following. I have xml that is versioned by a namespace.
I have an xml that has text within word elements e.g <word>Police</word> <word>confirmed</word> <word>they
So I have xml that looks like this: <todo-list> <id type=integer>#{id}</id> <name>#{name}</name> <description>#{description}</description> <project-id
I have an xml that looks like this: <Config> <A></A> <Template><B/><C/></Template> </Config> and I
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have an XML document that has an XML node named Description The Description
I have a XML file that has lot of elements with a particular attribute
I have an XML file that has certain properties and mappings defined in it.
I have a tiles-defs.xml that has these definitions... <definition name=masterLayout path=/WEB-INF/tiles-layouts/globalLayout.jsp> <put name=pageTemplate value=over-ride

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.