Nested foreach loop reading .xml and writing object to list c#

Lovester

New Member
I have a method that executes upon form_load event that seems to work properly omitting one line.\[code\]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; }\[/code\]The AddContact method adds the Employee object to a static list; however, the line:\[code\] this.AddContact(ccontact);\[/code\]is never executed.A sample of the XML file:\[code\]<?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>\[/code\]I have tried setting a breakpoint and debugging, and sure enough, the line is skipped over completed as if it were not even there.Any help appreciated.
 
Back
Top