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

  • Home
  • SEARCH
  • 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 8173353
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:07:01+00:00 2026-06-06T22:07:01+00:00

I have an XML file from which I am parsing some content to display

  • 0

I have an XML file from which I am parsing some content to display in a list:

Class:

public class SampleClass 
{
    public string Sample {get; set;}    
    public string Definite {get; set;}
    public string Random {get; set;}
}

XML File Sample:

<Question>
    <Sample>This is sample 1</Sample>
    <Definite>Answer 1</Definite>
</Question>

<Question>
    <Sample>This is sample 2</Sample>
    <Definite>Answer 2</Definite>
</Question>
...

Currently, I am parsing content from the list easily and making this list.

_list = xmlDoc.Descendants("Question")
              .Select(
                  q => new SampleClass 
                  { 
                      Sample = q.Element("Sample").Value, 
                      Definite = q.Element("Definite").Value
                  })
              .ToList();

However, in the list I want to include another element that is to be parsed from the XML file in a random order eg:

SampleClass list   Sample        Definite   Random 
                      ^              ^        ^ 
List element 1: This is sample 1, Answer 1, Answer5
List element 2: This is sample 2, Answer 2, Answer1
List element 3: This is sample 3, Answer 3, Answer4 ...

I wanted to ask how do I include this Random element in the list while parsing such that q.Random is assigned a random <Definite> Value </Definite> from the Question nodes?

Duplicates of random in the list are not acceptable.

  • 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-06T22:07:04+00:00Added an answer on June 6, 2026 at 10:07 pm

    Do it in 2 passes. The first pass can be identical to what you already have. The second pass will assign a random answer to each item in the list.

    This is off the top of my head, so forgive any bugs, but it will look something like the following:

    IList<string> randomAnswers = _list
        .Select(c => c.Definite)
        .OrderBy(c => Guid.NewGuid())
        .ToList();
    
    for (int index = 0; index < randomAnswers.Length; index++)
    {
        _list[index].Random = randomAnswers[index];
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class which is serialized to and from an XML file when
HI, I have some string from XML file, and I I want to replace
I am parsing an xml file from an API which I have converted into
I have some code which fetches an XML file from a URL and then
I have an xml file(from federal government's data.gov) which I'm trying to read with
I have a function TRANSLATE which reads value from the xml file based on
I have written simple code to get content from xml file to php. $xml
I have one problem , I want to get some data from XML file
I need to parse a XML file from the website.I have went through some
I'm parsing data from an xml file using WebClient. In DownloadStringCompleted method I have

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.