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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T08:40:11+00:00 2026-06-06T08:40:11+00:00

I’m having a bit of an issue. I’m trying to parse an XML file

  • 0

I’m having a bit of an issue. I’m trying to parse an XML file and put it’s contents into a TreeView. I got everything pretty much working, but I’m having issues with one thing.

Here is an example of the XML file:

<AnswerIt>

    <category name="Category 1">
        <question is="Question 1">
            <answer couldbe="Answer 1" />
            <answer couldbe="Answer 2" />
        </question>
    </category>

    <category name="Category 2">
        <question is="Question 1">
            <answer couldbe="Answer 1" />
        </question>
        <question is="Question 2">
            <answer couldbe="Answer 1" />
        </question>
    </category>

</AnswerIt>

The code I am using to prase the XML file pulls all the categories just fine. When it gets to the question part it pulls the first question, but none after that. All the answers get pulled just fine (as long as they belong to the first question). Here is my C# code:

public void LoadQuestionDatabase()
    {
        XmlTextReader reader = new XmlTextReader("http://localhost/AnswerIt.xml");


        TreeNode node = new TreeNode();
        TreeNode subnode = new TreeNode();

        while (reader.Read())
        {
            if (reader.NodeType == XmlNodeType.Element && reader.Name == "category")
            {
                node = lstQuestions.Nodes.Add(reader.GetAttribute(0));
                categories.Add(reader.GetAttribute(0));


                while (reader.NodeType != XmlNodeType.EndElement)
                {
                    reader.Read();
                    if (reader.Name == "question")
                    {
                       subnode = node.Nodes.Add(reader.GetAttribute(0));
                        questions.Add(reader.GetAttribute(0));

                        while (reader.NodeType != XmlNodeType.EndElement)
                        {
                            reader.Read();
                            if (reader.Name == "answer")
                            {
                                // add each answer
                                subnode.Nodes.Add(reader.GetAttribute(0).Replace("\t", ""));
                            }
                        }
                    }
                }

            }

        }
        reader.Close();
    }

I’m not very good at C#, I’m guessing somewhere along the lines it’s not looping through all the questions and adding them. Any ideas what I’m doing wrong? Anywhere I can read up on to help me out? Every example I read puts the root node (AnswerIt) in the treeview, and I do not want that.

  • 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-06T08:40:12+00:00Added an answer on June 6, 2026 at 8:40 am
    var xDocument = XDocument.Load("http://localhost/AnswerIt.xml");
    
    foreach (var element in xDocument.Descendants("category"))
    {
        var node = lstQuestions.Nodes.Add(element.Attribute("name").Value);
        foreach (var subElement in element.Elements("question"))
        {
            var subnode = node.Nodes.Add(subElement.Attribute("is").Value);
            foreach (var answer in subElement.Elements("answer"))
                subnode.Nodes.Add(answer.Attribute("couldbe")
                       .Value.Replace("\t", ""));
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a French site that I want to parse, but am running into
In my XML file chapters tag has more chapter tag.i need to display chapters
I am trying to render a haml file in a javascript response like so:
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
i want to parse a xhtml file and display in UITableView. what is the
i got an object with contents of html markup in it, for example: string
I'm parsing an XML file, the creators of it stuck in a bunch social
I am trying to loop through a bunch of documents I have to put
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

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.