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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:46:37+00:00 2026-05-25T18:46:37+00:00

I have a XML file that goes like this… (the XML file was taken

  • 0

I have a XML file that goes like this… (the XML file was taken from web services [WCF] after passing some value into it.)

<Title>
  <Questions>
    <QuestionID> 1 </QuestionID>
    <QuestionType> Quiz </QuestionType>
    <Question> What is the shape? </Question>
    <SubQuestionSequence> Part 1 </SubQuestionSequence>
    <SubQuestions>
           <Keywords> Ring </Keywords>
           <ParentQuestionID> 1 </ParentQuestionID>
    </SubQuestions>
    <SubQuestionSequence> Part2 </SubQuestionSequence>
    <SubQuestions>
           <Keywords> Round </Keywords>
           <ParentQuestionID> 1 </ParentQuestionID>             
    </SubQuestions>
  </Questions>
</Title>

The methods to take child elements as below (written in C#), the commented area is supposed to call the class of subQuestion, but i’m not sure how to write that part :

public class Questions {

    public int QuestionID { get; set; }
    public string QuestionType { get; set; }
    public string Question { get; set; }
    public string SubQuestionSequence { get; set; }            
    //suppose to call subQuestion here 
}

public class SubQuestion {

    public string Keywords { get ; set ; }
    public int ParentQuestionID { get; set; }

}

The actual code behind of the file, also the query area, i does not know how to call if they have another sub section:

void client_GetQuestionCompleted(object sender, GetQuestionCompletedEventArgs e)
{
     if (e.Error != null)
         return;

     string result = e.Result.Nodes[0].ToString();
     XDocument doc = XDocument.Parse(result);

     var QuestionDetails = from Query in doc.Descendants("QuestionDetail")
                           select new Questions
                           {
                                QuestionID = (int)Query.Element("QuestionID"),
                                QuestionType = (string)Query.Element("QuestionType"),
                                Question = (string)Query.Element("Question"),
                                SubQuestionSequence = (string)Query.Element("SubQuestionSequence")
                           };

     int z = 0;
     foreach (var QuestionDetail in QuestionDetails)
     {
           qID = QuestionDetail.QuestionID;
           qType = QuestionDetail.QuestionType;
           quest = QuestionDetail.Question;
           subQS = QuestionDetail.SubQuestionSequence;

           z++;

     }
}

As you can see from the top, how can i take the child elements of SubQuestions (The keywords and ParentQuestionID) where SubQuestion itself already is a child element ?

[edit] how can i retrieve the repeated element in the child element ? I want some part to loop and retrieve data, and some doesn’t need to loop to retrieve.

   int z = 0;
   foreach (var QuestionDetail in QuestionDetails)
   {
        qID = QuestionDetail.QuestionID;
        qType = QuestionDetail.QuestionType;
        quest = QuestionDetail.Question;
        subQS[z] = QuestionDetail.SubQuestionSequence;
        //doing it this way, i can only retrieve one row of record only, 
        //even though i used an array to save.
        subKeyword[z] = QuestionDetail.SubQuestion.Keywords;            

        z++;

   }
  • 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-25T18:46:37+00:00Added an answer on May 25, 2026 at 6:46 pm

    As long as there is only a single SubQuestions element you can simply access Query.Element("SubQuestions").Element("Keywords") respectively Query.Element("SubQuestions").Element("ParentQuestionID").

    [edit]
    As for you class with an object of the type SubQuestion you would simply use

    public class Questions {
    
        public int QuestionID { get; set; }
        public string QuestionType { get; set; }
        public string Question { get; set; }
        public string SubQuestionSequence { get; set; }            
        public SubQuestion SubQuestion{ get; set; }
    }
    
    public class SubQuestion {
    
        public string Keywords { get ; set ; }
        public int ParentQuestionID { get; set; }
    
    }
    

    and then in your query you can use e.g.

     var QuestionDetails = from Query in doc.Descendants("QuestionDetail")
                           select new Questions
                           {
                                QuestionID = (int)Query.Element("QuestionID"),
                                QuestionType = (string)Query.Element("QuestionType"),
                                Question = (string)Query.Element("Question"),
                                SubQuestionSequence = (string)Query.Element("SubQuestionSequence"),
                                SubQuestion = new SubQuestion() {
                                   Keywords = (string)Query.Element("SubQuestions").Element("Keywords"),
                                   ParentQuestionID = (int)Query.Element("SubQuestions").Element("ParentQuestionID")
                                }
                           };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

lets say i have an xml file path.xml that goes like this: <paths> <path
I have an xml file that looks like this; <Employee> <EmployeeName>Burt Reynolds</EmployeeName> <EmployeeTitle>Bad Ass</EmployeeTitle>
I have a piece of code that goes like this File file = null;
I have an XML file that looks like <?xml version='1.0' encoding='UTF-8'?> <root> <node name=foo1
I have an XML file that I would like to map some attributes of
I have an xml file that contains its element like <ab:test>Str</ab:test> When I am
If I have a line like this ContentRepository.Update(existing); that goes into datastore repository to
I have an XML file formatted like <paragraph> Some Free text goes here<LinkType1 href=link1
I have an XML document and a CSS file that goes with it, which
So I have some perl code that goes something like: use strict; use XML::XPath;

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.