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

The Archive Base Latest Questions

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

I have a method that executes upon form_load event that seems to work properly

  • 0

I have a method that executes upon form_load event that seems to work properly omitting one line.

private int ReadInPeople()
{
    XmlNodeList nodeList = m_xmlDoc.DocumentElement.ChildNodes;
    foreach (XmlNode PersonNode in nodeList)
    {
        Employee ccontact = new Employee();
        foreach (XmlNode PersonTag in PersonNode.ChildNodes)
        {
            switch (PersonTag.Name)
            {
                case "Employee":
                    ccontact.EmployeeNumber = PersonTag.FirstChild.Value;
                    break;
                case "FirstName":
                    ccontact.FirstName = PersonTag.FirstChild.Value;
                    break;
                case "LastName":
                    ccontact.LastName = PersonTag.FirstChild.Value;
                    break;
                default:
                    break;
            }
        }
        this.AddContact(ccontact);
    }
    return nodeList.Count;
}

The AddContact method adds the Employee object to a static list; however, the line:

this.AddContact(ccontact);

was not being executed.

A sample of the XML file:

<?xml version="1.0" encoding="utf-8"?>
<people>
  <person>
    <Employee>123456789</Employee>
    <FirstName>John</FirstName>
    <LastName>Smith</LastName>
  </person>
  <person>
    <Employee>987654321</Employee>
    <FirstName>Ellen</FirstName>
    <LastName>Wayne</LastName>
  </person>
</people>

I had tried setting a breakpoint and debugging, and sure enough, the line was skipped over completely as if it were not even there.

As per Alan’s advice, I changed the PersonTag.FirstChild.Value as it was attempting to reference a ChildNode that did not exist.

The updated, working method:

private int ReadInPeople()
{
    XmlNodeList nodeList = m_xmlDoc.DocumentElement.ChildNodes;
    foreach (XmlNode PersonNode in nodeList)
    {
        Employee ccontact = new Employee();
        foreach (XmlNode PersonTag in PersonNode.ChildNodes)
        {
            switch (PersonTag.Name)
            {
                case "Employee":
                    ccontact.EmployeeNumber = PersonTag.InnerText;
                    break;
                case "FirstName":
                    ccontact.FirstName = PersonTag.InnerText;
                    break;
                case "LastName":
                    ccontact.LastName = PersonTag.InnerText;
                    break;
                default:
                    break;
            }
        }
        this.AddContact(ccontact);
    }
    return nodeList.Count;
}
  • 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-15T22:01:44+00:00Added an answer on June 15, 2026 at 10:01 pm

    You can easily parse your xml with LINQ to XML:

    XDocument xdoc = XDocument.Load(path_to_xml);   
    var employees = xdoc.Descendants("person")
                        .Select(p => new Employee()
                        {
                            FirstName = (string)p.Element("FirstName"),
                            LastName = (string)p.Element("LastName"),
                            EmployeeNumber = (long)p.Element("Employee")
                        });
    
    foreach (var ccontact in employees)
        this.AddContact(ccontact);
    

    XmlDocument solution:

    XmlNodeList nodeList = m_xmlDoc.DocumentElement.SelectNodes("person");
    foreach (XmlNode PersonNode in nodeList)
    {
        Employee ccontact = new Employee();
        ccontact.LastName = PersonNode["LastName"].InnerText;
        ccontact.FirstName = PersonNode["FirstName"].InnerText;
        ccontact.EmployeeNumber = PersonNode["Employee"].InnerText;
        this.AddContact(ccontact);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some code in method C that will get executed based upon the
I have a form validation method that's called on submit. It executes a get
I have a Google Chrome extension that upon pressing a button executes an xmlhttp
I have two secondary threads,that executes the method WriteX as described below: static void
I have a very basic doubt regarding the method that gets executed when app
I have a service class that I need to execute a method on a
I have method that returns Drawable , and if its Bitmap object is recycled
I have method that returned NSManagedObject and I don't know what kind of NSManagedObject
I have method that returns module path of given class name def findModulePath(path, className):
I have a method that receives something and it needs to determine the type

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.