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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T02:59:10+00:00 2026-06-05T02:59:10+00:00

I’m making a small program that supposedly get all XML elements that can only

  • 0

I’m making a small program that supposedly get all XML elements that can only contain a value. For example (please refer to the image below), <Products> though it is an element, but it should not be displayed because it just encloses all other elements that can contain value, same for <Description> (the highlighted one, sorry for my english, but hope you get me guys..)

From the image below, my program should only pick the following elements:

<Material_Number> 

<Description> (the 2 elements but not including the highlighted one)

<Language>  
<Material_Type>  
<Base_Unit> 

What I actually get is nothing…

enter image description here

Kindly review my code and advise:

public MainForm()
        {
            InitializeComponent();

            XmlDataDocument xmldoc = new XmlDataDocument();
            XmlNode xmlnode;

            FileStream fs = new FileStream(@"C:\text.xml", FileMode.Open, FileAccess.Read);
            xmldoc.Load(fs);

            xmlnode = xmldoc.ChildNodes[1];
            GetElements(xmlnode);                       
        }

        void GetElements(XmlNode inXmlNode)
        {
            XmlNode xNode;
            XmlNodeList nodeList;

            int i = 0;

            if (inXmlNode.HasChildNodes)
            {
                nodeList = inXmlNode.ChildNodes;

                for (i = 0; i <= nodeList.Count - 1; i++)
                {
                    xNode = inXmlNode.ChildNodes[i];
                    string ss = xNode.Name;
                    GetElements(xNode);
                }
            }
            else
            {
                listBox1.Items.Add(inXmlNode.Name); 
            }
        }
  • 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-05T02:59:12+00:00Added an answer on June 5, 2026 at 2:59 am

    You could shorten your code a little but you should start calling to start at the first element.

      GetElements(xmldoc.ChildNodes[0]); 
    
        void GetElements(XmlNode inXmlNode)
        {
            if(inXmlNode.HasChildNodes)
            {
                foreach (XmlNode childNode in inXmlNode.ChildNodes)
                {
                    GetElements(childNode);
                }
            }
            else
            {
                listBox1.Items.Add(inXmlNode.ParentNode.Name);
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

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.